2016-11-10 4 views
17

Ich versuche, meine benutzerdefinierte zeichnende (Linie) für DividerItemDecoration, aber mit keinem Erfolg. Wo ist der Fehler?Set-Zeichen für DividerItemDecoration

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

XML Form:

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

By the way, brauchen Sie nicht 'DividerItemDecoration # setDrawable', können Sie einstellen,' android: listDivider' Attribut in Ihrem Thema statt. – arekolek

Antwort

27

Ändern der Form Rechteck.

Ex:

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