列表视图分隔边距 [英] Listview divider margin

查看:24
本文介绍了列表视图分隔边距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为 listview 分隔符设置边距.
分隔线是一条虚线:

I'm trying to set a margin to a listview divider.
The divider is a dashed line:

<?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 我在其中设置分隔符


and a listview where i set the divider

<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 忽略了填充.


but I want a divider margin left and right. I also tried to set a padding to the shape, but the listview is ignoring the padding.

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

<小时>

是否有可能为 listview 分隔符设置边距 - 除了在 Adapter 的 getView() 中?


Is there any possibility to set a margin to the listview divider - except in the getView() of the Adapter?

推荐答案

Inset is the way to go

Inset is the way to go

<?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>

这篇关于列表视图分隔边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆