本文翻译自: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: 这是一个示例的示例,该示例可以使用divider和dividerHeight参数在先前的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'