I am trying to create a LinearLayout with two Listviews and can not see the second Listview.
In the example you will see that I would like to have an image, then a title (for the first Listview), then the ListView. This should be followed by another title (for the second Listview) then the second ListView. I want both ListViews to scroll and not effect each other. Basically the idea is that a user can scroll through two different lists. This has been working nicely with just one ListView and just today I noticed I have a long forgotten Relativelayout (RelativeLayout01) that seems to being doing nothing.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bkgrnd"
android:orientation="vertical" >
<ImageView
android:id="@+id/test_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:paddingBottom="30sp"
android:paddingTop="30sp"
android:src="@drawable/title" />
<RelativeLayout
android:id="@+id/RelativeLayout01"
android:layout_width="716sp"
android:layout_height="wrap_content" >
</RelativeLayout>
<TextView
android:id="@+id/ title1_head"
android:layout_width="fill_parent"
android:layout_height="60sp"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="@string/ title1_head"
android:textColor="#ffffff"
android:textSize="12pt" />
<RelativeLayout
android:id="@+id/RelativeLayout02"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal" >
<ListView
android:id="@+id/ListView_Menu"
android:layout_width="716sp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:divider="@drawable/divider"
android:listSelector="@drawable/textured" >
</ListView>
</RelativeLayout>
<TextView
android:id="@+id/title2_head"
android:layout_width="fill_parent"
android:layout_height="60sp"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="@string/title2_head"
android:textColor="#ffffff"
android:textSize="12pt" />
<RelativeLayout
android:id="@+id/RelativeLayout03"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal" >
<ListView
android:id="@+id/ListView1_Menu"
android:layout_width="716sp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:divider="@drawable/divider"
android:listSelector="@drawable/textured" >
</ListView>
</RelativeLayout>
What appears to be happening is the first
ListViewis doing exactly as you told it and filling all available space and you’re making the Layout more complicated. Use only 1LinearLayoutand useandroid:weight="0"for the header and nonListViewviews andandroid:weight="1"for yourListViewviews. The weight will help you to control the height ofListViewviews.If you want more granular control over each group of header and list wrap them in their own
LinearLayoutand try not to put a weight on the contents of this layout as it can affect performance.