RecyclerView学习--item分割线

来源:互联网 发布:二维码点餐软件 编辑:程序博客网 时间:2024/04/27 08:17
        //添加分割线        recyclerView.addItemDecoration(new DividerItemDecoration(                MainActivity.this, DividerItemDecoration.VERTICAL));

最简单的方法是设置android已经实现的分割线。重写系统listDivider属性就达到了自定义分割线的目的了。

修改style.xml:

    <!-- Base application theme. -->    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">        <!-- Customize your theme here. -->        <item name="android:listDivider">@drawable/divider_bg</item>        <item name="colorPrimary">@color/colorPrimary</item>        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>        <item name="colorAccent">@color/colorAccent</item>    </style>

添加一个android:listDivider,覆盖系统的。

下drawable下新建一个divider_bg.xml:

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="rectangle" >    <solid android:color="@color/diver_color"/>    <size android:height="0.01dp"/></shape>

系统默认的太粗了,现在这样子大概个QQ、微信差不多了。
接上文RecyclerView学习–布局管理
参考文章:Android RecyclerView 使用完全解析 体验艺术般的控件

0 0