[英]How do I go about adding dividers for RecyclerView in android?
Currently, my RecyclerView is displaying correctly, but does not have dividers between each data set/item. 当前,我的RecyclerView正确显示,但是每个数据集/项目之间没有分隔符。
This is the code I'm using for my RecyclerView, with the layout of the the items displayed in the code snippet below. 这是我用于RecyclerView的代码,项目的布局显示在下面的代码片段中。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/relativeLayout">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
This is the code which determines how the items are arranged. 这是确定项目排列方式的代码。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:orientation="horizontal">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="3"
android:orientation="vertical">
<TextView
android:id="@+id/groupName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Group Name"
/>
<TextView
android:id="@+id/groupDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Group Date"
/>
<TextView
android:id="@+id/groupLocation"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Group Location"
/>
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/className"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="right"
android:text="Class Name"
/>
</LinearLayout>
</LinearLayout>
Here's a picture of what the app looks like, with the RecyclerView: http://imgur.com/WnJXkuV 这是带有RecyclerView的应用程序外观的图片: http : //imgur.com/WnJXkuV
You can add Divider as below 您可以如下添加分频器
recyclerView.addItemDecoration
(new DividerItemDecoration(MyActivity.this,
DividerItemDecoration.VERTICAL_LIST));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.