0

I am trying to implement a scrollview in one of my XML files but it doesnt seem to be working. It is cutting out the bottom 3 spinners and the last button in the XML. I guessed this is because I needed to scroll down to see them but I am unable to scroll?

Can anyone seem the issue?

XML

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
>

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

<TextView
    android:id="@+id/title"
    android:text="New Recipe"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"/>

<EditText
    android:id="@+id/recipeName"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/title"
    android:hint="Enter Recipe Name"/>

<ListView
    android:id="@+id/ingredientsList"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/recipeName"
    android:textColor="#000000"
    android:layout_above="@+id/showIngredientDialog"
    android:minHeight="150px">
</ListView>

<Button
    android:id="@+id/showIngredientDialog"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Add Ingredient"
    android:layout_above="@+id/showDirectionDialog"
    android:layout_alignParentStart="true"
    android:layout_marginBottom="145dp" />

<ListView
    android:id="@+id/directionsList"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="#000000"
    android:layout_above="@+id/showDirectionDialog"
    android:layout_alignParentStart="true"
    android:layout_marginBottom="37dp">
</ListView>

<Button
    android:id="@+id/showDirectionDialog"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Add Direction"
    android:layout_marginBottom="79dp"
    android:layout_alignParentBottom="true"
    android:layout_alignEnd="@+id/showIngredientDialog" />

<Spinner
    android:id="@+id/timeSpinner"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/showDirectionDialog"
    android:entries="@array/time"/>

<Spinner
    android:id="@+id/dietarySpinner"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:entries="@array/dietary"
    android:layout_below="@+id/showDirectionDialog"
    android:layout_toRightOf="@+id/timeSpinner" />

<Spinner
    android:id="@+id/heatSpinner"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:entries="@array/heat"
    android:layout_below="@+id/showDirectionDialog"
    android:layout_toRightOf="@+id/dietarySpinner" />

<Button
    android:id="@+id/saveRecipe"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Save Recipe"
    android:layout_below="@+id/timeSpinner"
    android:layout_alignParentBottom="true"
    android:layout_alignEnd="@+id/showDirectionDialog"
    android:layout_marginBottom="25dp" />


</RelativeLayout>
</ScrollView>
JJSmith
  • 1,833
  • 4
  • 17
  • 26

5 Answers5

0

Set the relativeLayout height to "wrap_content".

Sanf0rd
  • 3,644
  • 2
  • 20
  • 29
0
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<ScrollView 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
    android:id="@+id/title"
    android:text="New Recipe"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"/>

<EditText
    android:id="@+id/recipeName"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/title"
    android:hint="Enter Recipe Name"/>

<ListView
    android:id="@+id/ingredientsList"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/recipeName"
    android:textColor="#000000"
    android:layout_above="@+id/showIngredientDialog"
    android:minHeight="150px">
</ListView>

<Button
    android:id="@+id/showIngredientDialog"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Add Ingredient"
    android:layout_above="@+id/showDirectionDialog"
    android:layout_alignParentStart="true"
    android:layout_marginBottom="145dp" />

<ListView
    android:id="@+id/directionsList"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="#000000"
    android:layout_above="@+id/showDirectionDialog"
    android:layout_alignParentStart="true"
    android:layout_marginBottom="37dp">
</ListView>

<Button
    android:id="@+id/showDirectionDialog"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Add Direction"
    android:layout_marginBottom="79dp"
    android:layout_alignParentBottom="true"
    android:layout_alignEnd="@+id/showIngredientDialog" />

<Spinner
    android:id="@+id/timeSpinner"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/showDirectionDialog"
    android:entries="@array/time"/>

<Spinner
    android:id="@+id/dietarySpinner"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:entries="@array/dietary"
    android:layout_below="@+id/showDirectionDialog"
    android:layout_toRightOf="@+id/timeSpinner" />

<Spinner
    android:id="@+id/heatSpinner"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:entries="@array/heat"
    android:layout_below="@+id/showDirectionDialog"
    android:layout_toRightOf="@+id/dietarySpinner" />

<Button
    android:id="@+id/saveRecipe"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Save Recipe"
    android:layout_below="@+id/timeSpinner"
    android:layout_alignParentBottom="true"
    android:layout_alignEnd="@+id/showDirectionDialog"
    android:layout_marginBottom="25dp" />


</RelativeLayout>
</ScrollView>
</RelativeLayout>
Muhammad Younas
  • 1,543
  • 1
  • 22
  • 32
0

Your facing this issue because you are using ScrollView in which having ListView. Both having default scroll property which conflicting the issue. Check this SO post for resolving the issue.

Community
  • 1
  • 1
Pankaj
  • 7,908
  • 6
  • 42
  • 65
0

you can't put two scrolling widgets inside one another the will cause major issues even with normal scrolling

if there is no way to change this layout design please force a height to each listview but still the scroll will be buggy and you have to set extra margin on the side of list for the user to be able to scroll the parent scroll view

or try to break down the design if you can maybe tabs one for normal data and a tab for each list

Hala.M
  • 766
  • 6
  • 15
0
Because views of total heigt not bigger than screen height.
You can see with coding custom height. I hope below code help you.
I just change listview height.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
>

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

    <TextView
        android:id="@+id/title"
        android:text="New Recipe"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"/>

    <EditText
        android:id="@+id/recipeName"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/title"
        android:hint="Enter Recipe Name"/>

    <ListView
        android:id="@+id/ingredientsList"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/recipeName"
        android:textColor="#000000"
        android:layout_above="@+id/showIngredientDialog"
        android:minHeight="150px">
    </ListView>

    <Button
        android:id="@+id/showIngredientDialog"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Add Ingredient"
        android:layout_above="@+id/showDirectionDialog"
        android:layout_alignParentStart="true"
        android:layout_marginBottom="145dp" />

    <ListView
        android:id="@+id/directionsList"
        android:layout_width="fill_parent"
        android:layout_height="1000dp"
        android:textColor="#000000"
        android:layout_above="@+id/showDirectionDialog"
        android:layout_alignParentStart="true"
        android:layout_marginBottom="37dp">
    </ListView>

    <Button
        android:id="@+id/showDirectionDialog"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Add Direction"
        android:layout_marginBottom="79dp"
        android:layout_alignParentBottom="true"
        android:layout_alignEnd="@+id/showIngredientDialog" />

    <Spinner
        android:id="@+id/timeSpinner"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/showDirectionDialog"
        />

    <Spinner
        android:id="@+id/dietarySpinner"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:layout_below="@+id/showDirectionDialog"
        android:layout_toRightOf="@+id/timeSpinner" />

    <Spinner
        android:id="@+id/heatSpinner"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:layout_below="@+id/showDirectionDialog"
        android:layout_toRightOf="@+id/dietarySpinner" />

    <Button
        android:id="@+id/saveRecipe"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Save Recipe"
        android:layout_below="@+id/timeSpinner"
        android:layout_alignParentBottom="true"
        android:layout_alignEnd="@+id/showDirectionDialog"
        android:layout_marginBottom="25dp" />


</RelativeLayout>

Kadir altınok
  • 230
  • 2
  • 5