温馨提示:本文翻译自stackoverflow.com,查看原文请点击:android - Set drawable for DividerItemDecoration
android android-recyclerview

android - 为DividerItemDecoration设置可绘制

发布于 2020-03-29 21:53:20

我正在尝试为DividerItemDecoration设置我的自定义可绘制对象(线),但是没有成功。错误在哪里?

DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(getContext(),
                LinearLayoutManager.VERTICAL);
dividerItemDecoration.setDrawable(getContext().getResources().getDrawable(R.drawable.sk_line_divider));

XML形状:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="line">
    <stroke
        android:width="1dp"
        android:color="#000000">
    </stroke>
</shape>

查看更多

提问者
user3352926
被浏览
20
Jonathan Vicente 2016-11-15 22:46

将形状更改为矩形。

例如:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
    <size
        android:width="1dp"
        android:height="1dp" />
    <solid android:color="@color/primary" />
</shape>