我发现 DividerItemDecoration 可以很好地处理简单的单行列表项,但对于更复杂的列表项,它拒绝显示。这是列表项的 XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:orientation="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android" >
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/imageView"
android:transitionName="obrazek"
android:layout_marginRight="5dp" />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:background="?android:attr/selectableItemBackground">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/nazwa"
android:maxLines="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/odleglosc"
android:layout_gravity="right"
android:gravity="end"
android:layout_below="@+id/nazwa"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:clickable="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text=" "
android:id="@+id/cena"
android:layout_below="@+id/nazwa"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<!--
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ratingBar"
android:layout_below="@+id/nazwa"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
style="@style/beerRatingBar" />
-->
</RelativeLayout>
</LinearLayout>
我正在为 RecyclerView 使用最常见的装饰器。只是不知道为什么它不想画。
recyclerView.addItemDecoration(new DividerItemDecoration(
getApplicationContext(), DividerItemDecoration.VERTICAL_LIST));
Your RecyclerView
的方向是android:orientation="horizontal"
,但是你使用DividerItemDecoration.VERTICAL_LIST
。这是错误的。你应该使用DividerItemDecoration.HORIZONTAL
。这是违反直觉的:-)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)