简体   繁体   English

如何在ListView中显示最后一行的分隔线

[英]How do I show the divider for the last row in a ListView

I would like to make the divider for the last row appear so that the list "looks clean". 我想使最后一行的分隔线出现,以便列表“看起来很干净”。

My ListView has been "included" in another XML layout. 我的ListView已“包含”在另一个XML布局中。

I found that other posts show to use: 我发现其他帖子显示可以使用:

   android:layout_height="match_parent"

or 要么

    android:footerDividersEnabled="true"

Neither work for me. 都不适合我。 I know I have the right XML layout because I can set the divider color to RED, and it renders correctly. 我知道我有正确的XML布局,因为我可以将分隔线颜色设置为RED,并且可以正确呈现。

What am I missing? 我想念什么?

您可以为分隔线定义一个可绘制对象,并在列表视图下面的分隔线可绘制对象中添加一个带有背景设置的视图。

Add a line view below ListView : ListView下面添加一个线视图:

<View
    android:layout_width="match_perent"
    android:layout_height="1dp"
    android:padding="your_padding"
    android:background="@color/your_color"
    />   

If you are Inflating a custom view , you can add the following at the bottom of your custom view XML : 如果要扩展自定义视图,则可以在自定义视图XML的底部添加以下内容:

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="4dp"
android:background="#000000">
</RelativeLayout>

this will make a layout 4dp heigh black in color making it look like a line 4dp wide. 这将使布局4dp高度为黑色,使其看起来像4dp宽的线。

I ultimately had to do the following: 1) Create a custom divider xml such as: 我最终不得不执行以下操作:1)创建一个自定义分隔符xml,例如:

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <size android:height="1dip" />
        <solid android:color="@color/divider" />
    </shape> 

2) Then add the following to my LinearLayout widget. 2)然后将以下内容添加到我的LinearLayout小部件中。

        android:divider="@drawable/custom_list_divider"
        android:showDividers="end"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM