Divideritemdecoration does not display Android
•
Android
I have a simple layout for recycler view items
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/details"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:background="?android:attr/selectableItemBackground"
android:paddingEnd="15dp"
android:paddingStart="15dp"
>
<org.tchouaffe.ftinfosystem.utils.CustomTextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:textColor="@color/primaryTextColor"
android:textSize="15sp"/>
<org.tchouaffe.ftinfosystem.utils.CustomTextView
android:id="@+id/level"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_toRightOf="@id/name"
android:gravity="center_vertical|right"
android:textColor="@color/primaryTextColor"
android:textSize="15sp"/>
</RelativeLayout>
The following code does set the recycle bin view:
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recyclerview);
linearlayoutmanager layoutManager = new linearlayoutmanager(getActivity());
MyAdapter adapter = new MyAdapter(activity, elementList);
adapter.setHasStableIds(true);
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerView
.getContext(), DividerItemDecoration.VERTICAL);
recyclerView.addItemDecoration(dividerItemDecoration);
recyclerView.setHasFixedSize(false);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(adapter);
For unknown reasons, the separator line is not displayed. Do you have any ideas?
I'm using Android. Support. V7. Widget. Divideritemdecoration
thank you
resolvent:
You also need to call setdrawable() on dividerdecoration
Provide resources that can be drawn. XML shape drawable may be a good start. Shapes will be rendered as separators between recycler project views
Alternatively, when declaring the application topic, you can set the Android: listdivider project to the desired drawable
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码