I have used this code to display 2 list view one on top of the other.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#f00" >
</ListView>
<ListView
android:id="@+id/listView2"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#0f0" >
</ListView>
The problem is that, this causes the 2 listviews to each occupy half of the screen. I am adding a header to both lists like this.
LevelAdapter adapter = new LevelAdapter(getActivity(),
R.layout.list_item, weather_data);
View header = inflater.inflate(R.layout.header2, null);
View header2 = inflater.inflate(R.layout.header, null);
lv1.addHeaderView(header);
lv2.addHeaderView(header2);
lv1.setAdapter(adapter);
lv2.setAdapter(adapter);
I would like the header of the second list to appear after the first list is over. How do i do this?How do i make the listviews appear such that the second one starts when the first one is over ? Thanks
Adding layout_weight worked for me.
Use Like this:
Remove Linear layout. use relative layout and inside that place your two list view like this.
add Utility.java
In your Activity:
activity_main.xml
MainActivity.java
Try with relative layout:
It is not a good practice to use more than one ListViews' in a single container. It causes measuring and performance problems. Better is to use single ListView with several view types. In your case view types could be: listview1_viewtype, listview2_viewtype, listview2_header_viewtype. For first ListView's header you can use just header.
You should use
ExpandableListView
(http://developer.android.com/reference/android/widget/ExpandableListView.html). You would have two sections instead of two listviews but they (including headers) will be aligned as you described.