gpt4 book ai didi

android - DividerItemDecoration 没有出现在 RecyclerView 中

转载 作者:太空狗 更新时间:2023-10-29 16:34:22 28 4
gpt4 key购买 nike

我发现 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));

最佳答案

您的 RecyclerView 的方向是 android:orientation="horizo​​ntal",但您使用的是 DividerItemDecoration.VERTICAL_LIST。这是错误的。您应该使用 DividerItemDecoration.HORIZONTAL。这是违反直觉的:-)

关于android - DividerItemDecoration 没有出现在 RecyclerView 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32542639/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com