9

I have a dialog that has a list (a bunch of TextViews inside a LinearLayout) inside a ScrollView. The layout is as follows:

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

    <ProgressBar
        android:id="@+id/delete_progress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="gone" />

    <ScrollView
        android:id="@+id/filename_scroll"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:id="@+id/filename_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >
        </LinearLayout>
    </ScrollView>

    <View
        android:id="@+id/horisontal_separator"
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:background="@android:color/darker_gray" />

    <LinearLayout
        android:id="@+id/button_container"
        android:layout_width="match_parent"
        android:layout_height="48dp" >

        <Button
            android:id="@+id/load_button"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="@string/button_load"
            android:gravity="center"
            android:layout_weight="1" />

        <View
            android:layout_width="1dp"
            android:layout_height="fill_parent"
            android:background="@android:color/darker_gray" />

        <Button
            android:id="@+id/delete_button"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="@string/button_delete"
            android:gravity="center"
            android:layout_weight="1" />
    </LinearLayout>

</LinearLayout>

It looks like this with only a few items on the list: A few items on the list

But when there's more than can fit on the screen (and there's actual need to scroll), my buttons get pushed below the screen. When scrolling all the way to the bottom, it looks like this: A lot of items on the list

I need the LinearLayout containing the buttons to stay as footer, it shouldn't scroll anywhere and obviously not disappear. I've tried fiddling with the layout heights and weights, but to no avail.

j0ntech
  • 1,158
  • 3
  • 13
  • 27
  • Have you tried to set the ListView to a fixed height for example 200dip? – Demonick Apr 24 '13 at 08:55
  • I don't have an actual `ListView`there, but changing the `LinearLayout`'s height doesn't make a difference. And if I change the `ScrollView`'s height, it just pushes the buttons out again. – j0ntech Apr 24 '13 at 08:58

3 Answers3

25

try to change in scrollView

<ScrollView
    android:id="@+id/filename_scroll"
    android:layout_width="match_parent"
    android:layout_weight="1"
    android:layout_height="0dp" >
umesh
  • 1,148
  • 1
  • 12
  • 25
0

I think you should mention the Scrollview's layout_height explicitly like

<ScrollView
    android:id="@+id/filename_scroll"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" > ////say  android:layout_height="50dp"

    <LinearLayout
        android:id="@+id/filename_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
    </LinearLayout>
</ScrollView>

like that. And another option is, introduce an outer component like table layout by specifying the layout_height explicitly and include your scrollview as it is.

Hope it works

Shahid V
  • 11
  • 2
  • I don't want to specify anything explicitly, as it should change size depending on the number of items on the list. Anyway, umesh's answer did exactly what I needed. – j0ntech Apr 24 '13 at 09:13
  • Its works for me. The scrollview works as a container and I'm using dynamic content. more than 20nos. Anyway, glad you figure it out – Shahid V Apr 24 '13 at 10:25
0

Use below xml layout for custom dialog that you want to display,

<FrameLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ListView
        android:id="@+id/gameList"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="30dip" />

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

        <Button
            android:id="@+id/load"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Load" />

        <Button
            android:id="@+id/delete"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Delete" />
    </LinearLayout>
</FrameLayout>

And call it like this from your class file,

>     Button getList = (Button) findViewById(R.id.getList);
>     getList.setOnClickListener(new View.OnClickListener() {
>       
>             @Override
>       public void onClick(View v) {
>       // TODO Auto-generated method stub
>       final Dialog listDialog = new Dialog(MainActivity.this);
>       listDialog.setTitle("Load a game");
>       listDialog.setContentView(R.layout.custom_dialog);
>     
>       ListView gameList = (ListView) listDialog.findViewById(R.id.gameList);
>       gameList.setAdapter(new ArrayAdapter<String>          (MainActivity.this,android.R.layout.simple_list_item_1,new String[] {"your array" }));
>       
>       Button dismiss = (Button) listDialog.findViewById(R.id.load);
>       dismiss.setOnClickListener(new View.OnClickListener() {
>     
>           @Override
>           public void onClick(View v) {
>               // TODO Auto-generated method stub
>               listDialog.dismiss();
>                       }
>           });
>     
>           listDialog.show();
>       
>            } });
  • That `marginBottom` stuff is pretty clever, but I already got the answer. Also, my original layout didn't even have a `ListView`. Did you even read the question? – j0ntech Apr 24 '13 at 11:24
  • Hello jOntech,i already read it and i suggest you the alternate solution for it. And this sample serve your purpose and it is running sample.Did you check it? – Vishal Vaja Apr 24 '13 at 11:57