2011-08-03 35 views
1

我從android開發教程學到了,現在我可以創建ListView。它工作得很好。現在我的要求是我想顯示列表視圖與我在xml文件中創建的頁眉和頁腳。Android:顯示頁眉和頁腳之間的列表視圖

基本上在頂部會有一個頁眉頁腳&(文本視圖),然後如下列表視圖頁眉和頁腳之間滾動

能有人轉發我到適當的教程。

回答

3

您可能需要在你的XML 2 TextViews補充。一個在你的ListView之前,另一個在ListView之下。

2

這裏有一個帶有頁眉+頁腳的ListView代碼片段;

<LinearLayout android:id="@+id/lay_listitems" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical" 
       android:background="@drawable/white" 
       > 

       <TextView android:id="@+id/listview_items_header" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:textSize="@dimen/text_size_large" 
        android:textStyle="normal" 
        android:gravity="center_horizontal" 
        android:textColor="@drawable/titlecolor" 
        android:singleLine="true" 
        android:visibility="visible" 
        android:text=" --- HEADER ---" 
        /> 
       <ListView android:id="@+id/listview_items" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:drawSelectorOnTop="false" 
        android:smoothScrollbar="true" 
        android:focusable="true" 
        android:focusableInTouchMode="true" 
        android:clickable="true" 
        android:dividerHeight="1dip" 
        android:divider="@drawable/ltgray" 
        android:layout_gravity="center" 
        android:gravity="center" 
        /> 

       <TextView android:id="@+id/listview_items_footer" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:textSize="@dimen/text_size_large" 
        android:textStyle="italic" 
        android:gravity="center_horizontal" 
       android:textColor="@drawable/normaltextcolor" 
       android:singleLine="true" 
       android:visibility="visible" 
       android:text=" --- FOOTER --- " 
        /> 
      </LinearLayout> 

p.s.作爲額外的自定義顏色可以添加到colors.xml中,如下所示

<drawable name="titlecolor">#83a4cd</drawable> 
<drawable name="normaltextcolor">#83a4cd</drawable> 
<drawable name="gray">#585858</drawable> 
<drawable name="ltgray">#BDBDBD</drawable> 
<drawable name="extraltgray">#F2F2F2</drawable> 
1

這可能會很晚,但希望這可以幫助某人。 :-)

<?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:orientation="vertical"> 
    <TextView 
     android:text="Header" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"/> 
    <ListView 
     android:id="@android:id/listview1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"/> 
    <TextView 
     android:text="Footer" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom"/> 
</LinearLayout>