我正在使用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}" />

RISEBY
TA贡献1856条经验 获得超5个赞
您正在使用该线路
android:layout_height="wrap_content"
上你CardView
,又自后人有match_parent
,大小为你而变TextView
。
要解决此问题,您可以android:maxLines="1"
在TextView
. 这将阻止 TextView 跳转到下一行,但会裁剪文本。
或者,您可以使用静态高度而不是match_parent
or wrap_content
,即使用一个值。我强烈推荐使用48dp
,因为这是Material Design Guidelines推荐的。
添加回答
举报
0/150
提交
取消