0

Possible Duplicate:
How can I put a ListView into a ScrollView without it collapsing?

I am trying to make the food menu to scrollable but once i add it, it become like in the image. Before I add the scrollview, I cant view my back button in my screen eventhough I have added it. this is my weird code.

<?xml version="1.0" encoding="utf-8"?>
 <ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/foodbg"
    android:orientation="vertical" >

        <ListView
            android:id="@android:id/list"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp" />

        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:id="@+id/backToMenu"
            android:text="Back" >
        </Button>

</LinearLayout>

enter image description here

Community
  • 1
  • 1
shoujo_sm
  • 3,173
  • 4
  • 37
  • 60

2 Answers2

0

Hi, you can use RelativeLayout instead of LinearLayout.

In such case you should place your button at the bottom of the layout. After that place your list at the top of the layout and above the button. RelativeLayout has special xml-attributes to help you do this. After that you do not need a ScrollView.

Taras Feschuk
  • 689
  • 1
  • 6
  • 8
0
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="bottom"
    android:orientation="vertical" >

        <ListView
            android:id="@android:id/list"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:layout_weight="1" />

        <Button
            android:layout_width="fill_parent"
            android:layout_height="45dp"
            android:layout_gravity="bottom"
            android:id="@+id/backToMenu"
            android:text="Back" >
        </Button>

</LinearLayout>
</ScrollView>

Try to implement above code

Mitul Nakum
  • 5,514
  • 5
  • 35
  • 41