Android: ListView can't get full layout_height in ScrollView

1.3k views Asked by At


I have two questions:

- How to get a dynamic height(fill_parent, match_parent) for my ListView? If I write "layout_height: fill_parent" it's not really working

- How can I get a solution without ScrollView, only with the ListView? (Without ScrollView my scrollbar is too far away from right site.)

Greets Robin

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#e7e7e7">

<TextView
    android:id="@+id/date_header"
    android:layout_width="wrap_content"
    android:layout_height="30dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:background="#bfbfbf"
    android:gravity="center"
    android:text="05.07.2014"
    android:textAppearance="?android:attr/textAppearanceSmall" />

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_below="@+id/date_header"
    android:layout_centerHorizontal="true" >

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

        <ListView
            android:id="@+id/listView1"
            android:layout_width="match_parent"
            android:layout_height="431dp"
            android:divider="@android:color/transparent"
            android:dividerHeight="15dp"
            android:paddingBottom="20dp"
            android:paddingLeft="15dp"
            android:paddingRight="15dp"
            android:paddingTop="20dp"
            android:scrollbars="none" >

        </ListView>

    </LinearLayout>
</ScrollView>

1

There are 1 answers

2
Pratik Butani On

I think there is no need of ScrollView:

You may getting warning while designing like:

The vertically scrolling ScrollView should not contain another vertically scrolling widget (ListView)

You can achieve your design using this also:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:background="#e7e7e7" >

    <TextView
        android:id="@+id/date_header"
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:background="#bfbfbf"
        android:gravity="center"
        android:text="05.07.2014"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true"
        android:layout_below="@+id/date_header"
        android:layout_marginTop="10dp"
        android:divider="@android:color/transparent"
        android:dividerHeight="15dp"
        android:scrollbars="none" >
    </ListView>

</RelativeLayout>