为DividerItemDecoration设置可绘制 [英] Set drawable for DividerItemDecoration

查看:123
本文介绍了为DividerItemDecoration设置可绘制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to set my custom drawable (line) for DividerItemDecoration, but with no success. Where is the mistake?

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>

推荐答案

将形状更改为矩形.

例如:

<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>

这篇关于为DividerItemDecoration设置可绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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