为了账号安全,请及时绑定邮箱和手机立即绑定

Recyclerview 项目没有以相同的高度显示

Recyclerview 项目没有以相同的高度显示

慕运维8079593 2022-05-25 15:59:32
我正在使用RecyclerViewwith GridLayoutManager。我的问题正如您在图像中看到的,当其中一个项目的文本较长时,网格项目的高度不同。我正在从 firebase 加载数据,并在Adapter列表有数据时通知。我尝试了一切,但找不到像附加的第二张图片一样自动调整项目的解决方案。请问有什么帮助吗?这是我的 recyclerview 项目布局<FrameLayout    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:layoutDirection="rtl"    >    <android.support.v7.widget.CardView        android:layout_height="wrap_content"        android:layout_width="match_parent"        app:cardCornerRadius="10dp"        android:layout_margin="5dp"        app:cardBackgroundColor="#fff"        app:cardElevation="5dp"        >        <LinearLayout            xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"            android:layout_height="match_parent"            android:gravity="center"            android:orientation="vertical">            <ImageView                android:id="@+id/cartoonImg"                android:layout_width="match_parent"                android:layout_height="120dp"                android:scaleType="fitXY"                app:imgUrl="@{cartoon.thumb}"                />            <TextView                android:layout_width="wrap_content"                android:layout_height="match_parent"                tool:text="Cartoon Name"                android:gravity="center"                android:layout_marginTop="5dp"                android:layout_marginBottom="5dp"                android:layout_marginRight="2dp"                android:layout_marginLeft="2dp"                android:textColor="@color/colorPrimary"                android:text="@{cartoon.title}" />        </LinearLayout>    </android.support.v7.widget.CardView></FrameLayout>
查看完整描述

3 回答

?
白板的微信

TA贡献1883条经验 获得超3个赞

这将完全符合您的需要

尝试用TextView这个替换你的:

           <TextView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                tool:text="Cartoon Name"
                android:gravity="center"
                android:minLines="2"
                android:maxLines="2"
                android:ellipsize="end"
                android:layout_marginTop="5dp"
                android:layout_marginBottom="5dp"
                android:layout_marginRight="2dp"
                android:layout_marginLeft="2dp"
                android:textColor="@color/colorPrimary"
                android:text="@{cartoon.title}" />


查看完整回答
反对 回复 2022-05-25
?
RISEBY

TA贡献1856条经验 获得超5个赞

您正在使用该线路

android:layout_height="wrap_content"

上你CardView,又自后人有match_parent,大小为你而变TextView

要解决此问题,您可以android:maxLines="1"TextView. 这将阻止 TextView 跳转到下一行,但会裁剪文本。

或者,您可以使用静态高度而不是match_parentor wrap_content,即使用一个值。我强烈推荐使用48dp,因为这是Material Design Guidelines推荐的。


查看完整回答
反对 回复 2022-05-25
?
慕标琳琳

TA贡献1830条经验 获得超9个赞

你可以给你的文本视图一个静态高度,这样它对所有人都是一样的。但是您可能会在此丢失您的文本。



查看完整回答
反对 回复 2022-05-25
  • 3 回答
  • 0 关注
  • 203 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号