TableLayout with fixed section header and scrollable
-
23-06-2021 - |
Question
I am trying to create a view like this:
...that has two fixed headers. Whole table layout is scrollable and inner table view is also scrollable as shown in image. Headers and data are dynamic. And when I scroll up to header-2 it hides items of header-1 not header-1.
Solution
I can explain how you can accomplish it easily without using ListView. For less amount of data you should not use ListView it will affects your efficiency.
Step 1 :
Make use of weight attribute and give equal half for two header
Step 2:
Headers name be static , create one TableLayout inside Scroll View
Step 3:
Create TableRow as dynamic is separate or in same Layout and dynamically add Table row into the TableLayout.
Repeat the same for the Second Header you will get.
OTHER TIPS
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="list1" />
<ListView
android:id="@+id/list1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="vertical" />
<View
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#FF4500" />
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="list2" />
<ListView
android:id="@+id/con_listView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="vertical" />