如何显示水平 Recyclerview - 显示水平项目时遇到问题

我想在 recyclerview 中显示水平项目,但我已经尝试过,但没有成功,只显示具有放大宽度的水平项目。

在Android Studio中按我想要的方式显示

https://img1.sycdn.imooc.com/652798360001e11d03060099.jpg

但在我的移动设备中运行时,告诉我

https://img1.sycdn.imooc.com/652798400001f95306480381.jpg

这些项目是宽度换行的,但其他项目在滚动后出现,与我的上一个项目分开。


这是我的代码。


项目清单


<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:orientation="vertical">



    <LinearLayout

        android:id="@+id/linearFondo"

        android:layout_width="wrap_content"

        android:layout_height="50dp"

        android:background="@drawable/item_list_sel"

        android:orientation="horizontal">


        <ImageView

            android:id="@+id/imageView2"

            android:layout_width="20dp"

            android:layout_height="20dp"

            android:layout_gravity="center"

            app:srcCompat="@drawable/ruta"

            tools:srcCompat="@drawable/ruta" />


        <LinearLayout

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_gravity="center_vertical"

            android:layout_marginLeft="5dp"

            android:orientation="vertical">


            <TextView

                android:id="@+id/tnombre"

                android:layout_width="match_parent"

                android:layout_height="wrap_content"

                android:ellipsize="end"

                android:inputType="textMultiLine"

                android:lines="1"

                android:textAppearance="@style/TextAppearance.AppCompat.Medium"

                android:textSize="12sp"

                android:textStyle="bold"></TextView>

        </LinearLayout>


    </LinearLayout>

</LinearLayout>


PIPIONE
浏览 81回答 3
3回答

翻过高山走不出你

如果其他人有这个问题,我修复了在片段类中添加这一行。rlista.setHasFixedSize(true);

紫衣仙女

在您的 recyclerview 项目布局中,将这 2 个文本视图 [tnombre 和 thorarios] 的宽度更新为 wrap_content<LinearLayout&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="wrap_content"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="wrap_content"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_gravity="center_vertical"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_marginLeft="5dp"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:orientation="vertical">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <TextView&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:id="@+id/tnombre"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="wrap_content"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="wrap_content"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:ellipsize="end"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:inputType="textMultiLine"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:lines="1"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:textAppearance="@style/TextAppearance.AppCompat.Medium"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:textSize="12sp"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:textStyle="bold"></TextView>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <TextView&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:id="@+id/thorarios"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="wrap_content"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="wrap_content"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_gravity="center_vertical"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:textAppearance="@style/TextAppearance.AppCompat.Small"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:textColor="@color/colorPrimary"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:textSize="10sp"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:visibility="gone"></TextView>&nbsp; &nbsp; &nbsp; &nbsp; </LinearLayout>

慕尼黑5688855

我想你只需在你的类适配器中添加notifyDataSetChangedpublic rutaSelAdapter(List<Ruta> l, onItemClick onclick) {&nbsp; &nbsp; &nbsp; &nbsp; lista = l;&nbsp; &nbsp; &nbsp; &nbsp; this.onItemClick = onclick;&nbsp; &nbsp; &nbsp; &nbsp; if (l.size() > 0)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setSelectedItem(l.get(0));&nbsp; &nbsp; &nbsp; &nbsp; notifyDataSetChanged();&nbsp; &nbsp; }
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java