如何在 Android RecyclerView 中添加分隔线? [英] How can a divider line be added in an Android RecyclerView?

查看:24
本文介绍了如何在 Android RecyclerView 中添加分隔线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用 RecyclerView 的 android 应用程序.我需要在 RecyclerView 中添加一个 divider.我试图添加 -

I am developing an android application where I am using RecyclerView. I need to add a divider in RecyclerView. I tried to add -

recyclerView.addItemDecoration(new
     DividerItemDecoration(getActivity(),
       DividerItemDecoration.VERTICAL_LIST));

下面是我的 xml 代码 -

below is my xml code -

   <android.support.v7.widget.RecyclerView
    android:id="@+id/drawerList"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="15dp"
    />

推荐答案

在 2016 年 10 月的更新中,支持库 v25.0.0 现在提供了基本水平和垂直分隔线的默认实现!

In the October 2016 update, the support library v25.0.0 now has a default implementation of basic horizontal and vertical dividers available!

https://developer.android.com/reference/android/support/v7/widget/DividerItemDecoration.html

 recyclerView.addItemDecoration(new DividerItemDecoration(recyclerView.getContext(), DividerItemDecoration.VERTICAL));

这篇关于如何在 Android RecyclerView 中添加分隔线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆