2016-11-10 52 views
17

我想为DividerItemDecoration设置我的自定义绘制(线),但没有成功。错误在哪里?为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> 
+2

顺便说一句,你不需要'DividerItemDecoration#setDrawable',您可以设置'机器人:在你的主题listDivider'属性来代替。 – arekolek

回答

27

改变形状为矩形。

例:

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