2011/02/27

Android - 固定ヘッダー付きのListView - その1

固定ヘッダー付きのListViewを使用する場合 (Webページでいう position:fixed; のヘッダー)

ヘッダーに 「Left Button」「Center Button」「Right Button」を配置した場合は以下のようにすればOK

こんな感じになります。(スクロールしても、ヘッダーの部分は固定です。)


  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.  android:layout_width="wrap_content"  
  4.  android:layout_height="wrap_content"  
  5.  >  
  6.  <LinearLayout  
  7.   android:id="@+id/header_menu"  
  8.   android:layout_width="fill_parent"  
  9.   android:layout_height="wrap_content"  
  10.      android:orientation="horizontal"  
  11.   >  
  12.   <Button  
  13.    android:layout_width="wrap_content"  
  14.    android:layout_height="wrap_content"  
  15.    android:text="Left Button"  
  16.    />  
  17.   <Button  
  18.    android:layout_width="wrap_content"  
  19.    android:layout_height="wrap_content"  
  20.    android:text="Center Button"  
  21.    android:layout_weight="1"  
  22.    />  
  23.   <Button  
  24.    android:layout_width="wrap_content"  
  25.    android:layout_height="wrap_content"  
  26.    android:text="Right Button"  
  27.    />  
  28.  </LinearLayout>  
  29.  <ListView  
  30.   android:layout_width="fill_parent"  
  31.   android:layout_height="wrap_content"  
  32.   android:id="@+id/ListViewSample"  
  33.   android:layout_below="@id/header_menu"  
  34.   >  
  35.  </ListView>  
  36. </RelativeLayout>  

フッターもつけたい場合は,
http://blog.maxaller.name/2010/05/attaching-a-sticky-headerfooter-to-an-android-listview/
を参考にするとよし。

0 コメント:

コメントを投稿

 
;