繁体   English   中英

Android listview-仅在列表末尾添加分隔线

[英]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.

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