简体   繁体   English

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

[英]Android listview - Add a divider only at the end of the list

I'm creating a custom drawer view which has multiple listViews. 我正在创建一个具有多个listViews的自定义抽屉视图。 To show this nicely to the user I want to separate these listViews with a divider. 为了很好地向用户显示,我想用分隔线将这些listViews分开。

I've managed to show the dividers between the items, and even get the last one to show a divider, but not just the last item. 我设法显示了项目之间的分隔线,甚至得到了最后一个显示分隔线的对象,而不仅仅是最后一个项目。

I know I can toggle the dividers with 我知道我可以用

android:footerDividersEnabled="false"
android:headerDividersEnabled="false"

But that is not the desired effect (dividers between each listitem). 但这不是期望的效果(每个列表项之间的分隔符)。 I just need a line underneath the list. 我只需要在列表下面一行。

My ListView XML at this point: 我的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" />

Is there any way to achieve this effect? 有什么办法可以达到这种效果?

Thanks in advance. 提前致谢。

EDIT: I'm aware that I can put a view of 1dp height underneath the list. 编辑:我知道我可以在列表下面放置一个1dp高度的视图。 But I'm looking for an option within the list view. 但是我正在列表视图中寻找一个选项。 If that's not possible, which it's starting to look like. 如果那不可能,那就开始看起来像。 I'll go with that solution. 我将采用该解决方案。 Bit dirty in my opinion, but it can't be helped. 我认为有点脏,但是这无济于事。

You could simply add a 1dp high View between your listviews. 您可以在列表视图之间简单地添加1dp高视图。

</ListView>
<View
   android:layout_height="1dp"
   android:layout_width="match_parent"
   android:background="@android:color/red"
/>

In your drawer layout add: 在您的抽屉布局中添加:

<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" />

You can add view a the end of list using addFooterView (View v) . 您可以使用addFooterView (View v)将视图添加到列表的末尾。 More info here 更多信息在这里

And looks like you will need to do this from code. 并且看起来您将需要通过代码执行此操作。

For setting divider only at the last item of listview you can View or put horizontal line in imageview . 若要仅在listview的最后一项设置分隔线,可以查看或在imageview中放置水平线。

      <ImageView
        android:id="@+id/imageseprator"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/strip" />

Or 要么

     <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