如何在RecyclerView中的项目之间添加分隔线和空格?

本文介绍了如何在Android的RecyclerView中添加分隔线和项目间的空格。通过使用DividerItemDecoration,自定义ItemDecoration或者调整布局间距来实现。示例代码和库资源提供了详细的操作方法。
摘要由CSDN通过智能技术生成

本文翻译自:How to add dividers and spaces between items in RecyclerView?

This is an example of how it could have been done previously in the ListView class, using the divider and dividerHeight parameters: 这是一个示例的示例,该示例可以使用dividerdividerHeight参数在先前的ListView类中完成:

<ListView
    android:id="@+id/activity_home_list_view"
    android:layout_width="match_parent" 
    android:layout_height="match_parent"
    android:divider="@android:color/transparent"
    android:dividerHeight="8dp"/>

However, I don't see such possibility in the RecyclerView class. 但是,我在RecyclerView类中看不到这种可能性。

<android.support.v7.widget.RecyclerView
    android:id="@+id/activity_home_recycler_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="vertical"/>

In that case, is it ok to define margins and/or add a custom divider view directly into a list item's layout or is there a better way to achieve my goal? 在那种情况下,可以定义边距和/或将自定义分隔符视图直接添加到列表项的布局中,还是有更好的方法实现我的目标?


#1楼

参考:https://stackoom.com/question/1fITt/如何在RecyclerView中的项目之间添加分隔线和空格


#2楼

Might I direct your attention to this particular file on Github by Alex Fu: https://gist.github.com/alexfu/0f464fc3742f134ccd1e 我是否可以将您的注意力转移到Alex Fu在Github上的特定文件上: https : //gist.github.com/alexfu/0f464fc3742f134ccd1e

It's the DividerItemDecoration.java example file "pulled straight from the support demos".( https://plus.google.com/103498612790395592106/posts/VVEB3m7NkSS ) 这是DividerItemDecoration.java示例文件“直接从支持演示中提取”。( https://plus.google.com/103498612790395592106/posts/VVEB3m7NkSS

I was able to get divider lines nicely after importing this file in my project and add it as an item decoration to the recycler view. 在我的项目中导入此文件并将其作为项装饰添加到回收视图后,我能够很好地获得分隔线。

Here'

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值