[英]Why divider is not showing in the listview @android:id/list ?
[英]Android listview - Add a divider only at the end of the list
我正在創建一個具有多個listViews的自定義抽屜視圖。 為了很好地向用戶顯示,我想用分隔線將這些listViews分開。
我設法顯示了項目之間的分隔線,甚至得到了最后一個顯示分隔線的對象,而不僅僅是最后一個項目。
我知道我可以用
android:footerDividersEnabled="false"
android:headerDividersEnabled="false"
但這不是期望的效果(每個列表項之間的分隔符)。 我只需要在列表下面一行。
我的ListView XML此時:
<ListView android:id="@+id/list_view_drawer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="false"
android:choiceMode="singleChoice"
android:divider="@color/progress_gray"
android:footerDividersEnabled="false"
android:headerDividersEnabled="false"
android:dividerHeight="1dp"
android:background="#fff" />
有什么辦法可以達到這種效果?
提前致謝。
編輯:我知道我可以在列表下面放置一個1dp高度的視圖。 但是我正在列表視圖中尋找一個選項。 如果那不可能,那就開始看起來像。 我將采用該解決方案。 我認為有點臟,但是這無濟於事。
您可以在列表視圖之間簡單地添加1dp高視圖。
</ListView>
<View
android:layout_height="1dp"
android:layout_width="match_parent"
android:background="@android:color/red"
/>
在您的抽屜布局中添加:
<ListView android:id="@+id/list_view_drawer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="false"
android:choiceMode="singleChoice"
android:background="#fff" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/progress_gray"/>
<ListView android:id="@+id/list_view_drawer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="false"
android:choiceMode="singleChoice"
android:background="#fff" />
您可以使用addFooterView (View v)
將視圖添加到列表的末尾。 更多信息在這里
並且看起來您將需要通過代碼執行此操作。
若要僅在listview的最后一項設置分隔線,可以查看或在imageview中放置水平線。
<ImageView
android:id="@+id/imageseprator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/strip" />
要么
<View
android:id="@+id/imageseprator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/strip"/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.