-1


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>

robtothein
  • 23
  • 5

1 Answers1

0

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>
Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
  • the header view should probably be in a new xml file, and use `addHeaderView` to set it. – LordRaydenMK Jul 05 '14 at 17:56
  • @LordRaydenMK No, you don't need to use `addHeaderView` (nor `addFooterView`). If you have a design that `already includes` a Header (and/or a Footer). – Phantômaxx Jul 05 '14 at 19:08