[英]How to set width of ListView divider?
如何設置自定義ListView分隔符的寬度,以使其小於行寬?
RecyclerView
通常比現在使用ListView
。 有關如何在RecyclerView
設置分隔線寬度的信息,請參閱此問答 。
<inset>
繪制/ list_divider.xml
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetLeft="10dp"
android:insetRight="10dp" >
<shape android:shape="rectangle" >
<solid android:color="@color/list_divider_color" />
</shape>
</inset>
在你的布局中:
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="#00000000"
android:divider="@drawable/list_divider"
android:dividerHeight="1dp" >
</ListView>
資料來源:
制作一個9補丁png,左右兩側都有透明像素。 例如,一個53x4 .9.png,其兩側有25個透明像素(+像素到9個像素)會將1個像素拉伸,因此其兩側有25個像素。
如果你不想制作9個補丁,那么你可以插入
<View android:layout_width="fill_parent" android:layout_height="1dp" android:layout_marginTop="4dp" android:background="#33B5E5" />
在list_item的xml代碼中。 它會創建一條藍線,您可以輕松控制該線的寬度。 要使此成功,您必須禁用listview的分隔符。 這是考慮這里
你應該可以打電話
mListView.setDivider(Drawable d);
並將其傳遞給您可以包含在res / drawable文件夾中的drawable。 如果你想讓它幾乎一直走到你身邊就可以制作一個包含水平線的9補丁,左右兩側都有你想要的透明度。 並將其設置為拉伸線的中間部分。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.