列表视图分频器保证金(Listview divider margin)

2019-06-25 14:10发布

我想一个边距设置为一个listview分频器。
分频器为虚线:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="line" >
    <stroke
        android:dashGap="1dp"
        android:dashWidth="1.5dp"
        android:width="1dp"
        android:color="#FF404040" />

    <size android:height="3dp" />

</shape>

listview ,其中i设置分隔

<ListView
    android:id="@+id/lv_news_feed_list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/white"
    android:divider="@drawable/ch_dashed_line_divider"
    />

但我想留下一个除法缘和右 。 我也试着填充设置的形状,但listview是忽略了填充。

    <padding
        android:bottom="15dp"
        android:left="15dp"
        android:right="15dp"
        android:top="15dp" />

是否有可能来设置保证金的listview除法-除了在适配器的getView()?

Answer 1:

插图是要走的路

<?xml version="1.0" encoding="UTF-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
    android:insetLeft="15dp"
    android:insetRight="15dp" >

    <shape
        android:shape="line" >
        <stroke
            android:dashGap="1dp"
            android:dashWidth="1.5dp"
            android:width="1dp"
            android:color="#FF404040" />

            <size android:height="3dp" />

    </shape>

</inset>


Answer 2:

使用“插入” .....

(list_divider.xml)

<?xml version="1.0" encoding="UTF-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
    android:insetLeft="50dp"
    android:insetRight="50dp" >

 <shape>
    <solid android:color="@color/orange" />
    <corners android:radius="2.0dip" />
</shape>

</inset>

在您的列表视图中添加这样的...

<ListView
    android:dividerHeight="2dp"
    android:divider="@drawable/list_divider"
    ...
/>

您可以根据需要设置插入值...



Answer 3:

您可以使用以下的想法:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="rectangle">
        <solid android:color="@color/table_background"/>
    </shape>
</item>
<item android:left="2dp" android:right="2dp">
    ... your shape here ...
</item> </layer-list>

这个对我有用。 希望这将有助于。



Answer 4:

U可以用梯度来获得的,而不是中风左,右缘..试试这个样品是开始,以黑色结束时,使中心获得日子会把你白色。它看起来像u've给出保证金

 <gradient android:startColor="#000000" android:centerColor="#ffffff"
    android:endColor="#000000" />


Answer 5:

I don't believe it is possible :/ Although if you add your own drawable at the bottom of each list item and remove the ListViews divider you can customize it however you want :)

Create the folder res/drawable and create a new xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <solid android:color="#666666"></solid>

</shape>

..Then use that drawable in you list item.

Or a really quick and dirty way would ofc to create a thin LinearLayout (or some other layout) with colored background at the bottom of the list item to fake a customizable ListView divider..

Not a proper sollution, just some fixit ideas ;)



文章来源: Listview divider margin