2012-08-27 59 views
18

我的理解是,爲列表視圖定義的分隔線應該出現在列表的頂部和底部,即在第一個項目的上方和最後一個項目的下方。頂部和底部的分隔線不顯示在Android列表視圖

因爲他們不會出現在我的列表視圖某些原因:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/mainLayout" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@drawable/background"> 

<ImageView 
    android:id="@+id/home" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:paddingLeft="3dp" 
    android:paddingTop="3dp" 
    android:paddingBottom="3dp" 
    android:src="@drawable/homeicon"/> 

<TextView 
    android:id="@+id/titleBar" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Page Title" 
    android:layout_marginLeft="10dp" 
    android:paddingTop="3dp" 
    android:textSize="18sp" 
    android:textStyle="bold" 
    android:typeface="serif" 
    android:textColor="#FFFFFF" 
    android:layout_centerHorizontal="true"/> 

<ImageView 
    android:id="@+id/back" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:paddingRight="8dp" 
    android:paddingTop="8dp" 
    android:src="@drawable/backicon" 
    android:layout_alignParentRight="true"/> 


<ImageView 
    android:id="@+id/separator1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/home" 
    android:scaleType="fitXY" 
    android:src="@drawable/separatorimg" /> 


<ListView 
    android:id="@android:id/android:list" 
    android:layout_below="@+id/separator1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:cacheColorHint="#00000000" 
    android:divider="@drawable/separatorimg"> 
</ListView> 

</RelativeLayout> 

設置機器人:footerDividersEnabled爲true(這是在圍繞這個問題其他問題給出的答案)不會改變任何東西。此外,我沒有禁用的項目,除非有某種默認頁腳會被禁用。

任何想法?

編輯:當我滾動過第一個/最後一個項目,然後消失時,似乎頂部和底部的分隔線出現一瞬間。它看起來好像接口將繼續,只是在後來才意識到這是最後一項,然後禁用分頻器。

回答

0

我想你必須使用列表視圖下方的視圖來設置頁腳。我有同樣的問題,這就是我能得到作爲一個解決方案:

Show divider after the last item in the list

+0

感謝您的回答,不幸的是,這並不適合我。首先,該視圖僅顯示其下面是否有其他元素(不知道爲什麼),其次,即使顯示,它仍保持始終可見在屏幕的底部。我試圖達到的效果是,分頻器只出現在列表的末尾,就像它隨着它滾動一樣。 – InterRaptor

+0

你嘗試過嗎?因爲它按照你想要的方式工作 –

+0

我試了一下,在接受的答案中複製了代碼(替換listview id)在listview下方。即使有許多列表項目仍然需要滾動,我仍然會在屏幕底部出現一條綠線。 – InterRaptor

0

請看以下修改後的代碼:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/mainLayout" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@drawable/background" > 

<LinearLayout 
    android:id="@+id/llAppBar" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:orientation="horizontal" 
    android:weightSum="10" > 

    <ImageView 
     android:id="@+id/home" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="2" 
     android:paddingBottom="3dp" 
     android:paddingLeft="3dp" 
     android:paddingTop="3dp" 
     android:scaleType="fitXY" 
     android:src="@drawable/homeicon" /> 

    <TextView 
     android:id="@+id/titleBar" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
     android:layout_weight="6" 
     android:paddingTop="3dp" 
     android:text="Page Title" 
     android:textColor="#FFFFFF" 
     android:textSize="18sp" 
     android:textStyle="bold" 
     android:typeface="serif" /> 

    <ImageView 
     android:id="@+id/back" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="2" 
     android:paddingRight="8dp" 
     android:paddingTop="8dp" 
     android:scaleType="fitXY" 
     android:src="@drawable/backicon" /> 
</LinearLayout> 

<ImageView 
    android:id="@+id/separator1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/llAppBar" 
    android:scaleType="fitXY" 
    android:src="@drawable/separatorimg" /> 

<ListView 
    android:id="@android:id/android:list" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/separator1" 
    android:cacheColorHint="#00000000" 
    android:divider="@drawable/separatorimg" > 
</ListView> 

</RelativeLayout> 
+0

我想你已經添加了LinearLayout以便能夠使用重量。好主意,但沒有運氣,仍然沒有出現頂部或底部的分隔線。 – InterRaptor

4

我有同樣的問題。下面是我如何解決它:

<ListView 
    android:id="@+id/my_list" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:divider="@color/transparent" 
    android:dividerHeight="@dimen/padding_default" 
    android:footerDividersEnabled="false" 
    android:headerDividersEnabled="false" > 
</ListView> 

然後,在onCreate()方法,我有:

View v = new View(this); 
v.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 1)); 
mList.addFooterView(v); 
28

我解決了使用幫助,從以下鏈接這個問題:Divider disappears from last item in listview if footerview added

我確實添加了

android:footerDividersEnabled="true" 

屬性爲XML中的ListView。然後編程,我說那是可選擇空頁腳視圖使用

listView.addFooterView(new View(context), null, true); 

我沒有嘗試的頭,但我希望它的工作方式相同。

+0

對我來說,只有當頁腳被標記爲可選時,分隔符纔會出現,即對'addFooterView'的最後一個參數是'true'。將其設置爲「false」不會顯示分隔符。 – nickgrim

-2

我有同樣的問題,並設置填充和背景顏色解決它。

<ListView 
    android:id="@+id/list" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/gray_background" 
    android:paddingTop="1dp" 
    android:paddingBottom="1dp"   
/> 

在這裏,背景顏色應該與帶有列表視圖的分隔線的顏色相同。

+0

當您滾動時,此解決方案不會消失 – Hrk

相關問題