具有固定标题的Android Listview表

时间:2015-06-30 13:19:43

标签: android android-layout listview

我需要一个带固定标题的表格。它有100-200个条目 我遇到了性能问题 - 100多行渲染速度非常慢。

已经回答了类似的问题 - Android TableLayout with over 1000 rows loading very slowly

建议使用Listview。

但问题是,我找不到一种方法来制作一个Listview表,其中包含固定且正确对齐的标题。有没有办法制作一个所有列宽度相等的固定标题?

编辑:顶行必须始终位于页面顶部,列名称与主表格正确对齐

2 个答案:

答案 0 :(得分:0)

Depends, do you need the header to be able to scroll as well ? Or does it need to be always visible ?

  • Needs to scroll : use addHeaderView
  • Does not need to scroll : add a View over your ListView

The HeaderView will have a layout similar to your cells (to have the same column widths)

答案 1 :(得分:0)

I understant you want a fixed view with above your ListView. It is possible using RelativeLayout

<RelativeLayout
      android:width="fill_parent"
      android:height="fill_parent"
      />
      <!-- the header -->
      <LinearLayout 
           android:id="@+id/header"
           android:width="fill_parent"
           android:height="wrap_content"
           android:orientation="horizontal"
           android:weightSum="4"
           >
           <TextView
                android:width="0dip"
                android:height="wrap_content"
                android:text="case 1"
                android:weight="1"
                />
           <TextView
                android:width="0dip"
                android:height="wrap_content"
                android:text="case 2"
                android:weight="1"
                />
           <TextView
                android:width="0dip"
                android:height="wrap_content"
                android:text="case 3"
                android:weight="1"
                />
           <TextView
                android:width="0dip"
                android:height="wrap_content"
                android:text="case 4"
                android:weight="1"
                />
       </LinearLayout>
       <ListView
            android:width="fill_parent"
            android:height="fill_parent"
            android:layout_below="@+id/header"
            />
   </RelativeLayout>