在我的應用程序中,我使用的回收視圖,其中包含一些項目,我想顯示項目之間的一個溺愛分隔符(分隔線),但它不工作。我試圖創建一個可繪製的形狀,但添加繪圖到DividerItemDecoration沒有空間或行之間顯示的回收商查看項目。 我曾嘗試創建自定義的DividerItemDecoration類,但沒有爲我工作。 注意:目前在我的可繪製形狀設置爲矩形我也試過線。 如何實現。任何幫助將不勝感激。 這是我的代碼。分隔線不顯示在回收查看項目
繪製對象:(customdrawableshape.xml)
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="3dp"
android:height="2dp"
android:color="#000000"
android:dashGap="10dp"
android:dashWidth="5dp" />
</shape>
自定義行的回收視圖中的項目
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginBottom="2dp">
<TextView
android:id="@+id/tv_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
和代碼的部分我在哪裏設置項裝飾recyclerview
DividerItemDecoration dividerItemDecoration;
recyclerview.setLayoutManager(linearlayoutmanager);
dividerItemDecoration = new DividerItemDecoration(recyclerview.getContext(),
linearlayoutmanager.getOrientation());
dividerItemDecoration.setDrawable(ContextCompat.getDrawable(context, R.drawable.customdrawableshape));
recyclerview.addItemDecoration(dividerItemDecoration);
是recyclerview一個錯字後,額外的點'.'? – BlackHatSamurai
[Android的 - 如何爲RecyclerView添加虛線/點分隔線?](http://stackoverflow.com/questions/39667195/android-how-to-add-a-dashed-dotted-separator-line -for-recyclerview) – BlackHatSamurai
@BlackHat武士哦是的,這是一個打字錯誤在這裏 – User