2016-11-10 3 views
17

DividerItemDecorationのカスタム描画可能線(線)を設定しようとしていますが、成功しません。間違いはどこですか?DividerItemDecorationのDrawableを設定します。

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

ところで、あなたは'アンドロイドを設定することができます。 – arekolek

答えて

27

変更矩形に形状。

例:代わりにあなたのテーマでlistDivider`属性:あなたは `DividerItemDecoration#setDrawable`を必要としない

<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> 
関連する問題