【发布时间】:2019-07-07 15:03:30
【问题描述】:
我有一个带有 GridLayoutMananger 的回收器视图,由于某种原因,同一行中的所有项目都具有相同的高度 它看起来像这样:
如您所见,所有元素都具有相同的高度。我在图片上画的红线下方有一个空白区域;我希望它被删除。 正确的项目比其他项目的高度更高,因此其他两个项目的高度相同。
我希望每个项目都达到它需要的高度,而不是更多。
这里是java代码:
GridLayoutManager layoutManager = new GridLayoutManager(this,3 );
recycle_confirm_command = (RecyclerView) findViewById(R.id.recycle_all_command);
recycle_confirm_command.setLayoutManager(layoutManager);
adapter = new ListCommandAdapter(this, List_to_confirm, btn_total);
recycle_confirm_command.setAdapter(adapter);
这里是项目的 XML 适配器:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
card_view:cardBackgroundColor="@color/UnderPrim"
card_view:cardCornerRadius="10dp"
android:background="@drawable/my_button_xml">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/lbl_command"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:text="eeee\nrfkfkkf\nfkfkfkf\ndkdkdkd\j\nkdkdkd"
android:layout_toLeftOf="@id/lbl_time_of_command"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/lbl_time_of_command"
android:layout_width="wrap_content"
android:text="time"
android:layout_alignLeft="@id/lbl_numer_of_command"
android:layout_alignParentRight="true"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/lbl_numer_of_command"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:gravity="bottom"
android:layout_alignBottom="@id/lbl_command"
android:text="numéro"
android:layout_below="@id/lbl_time_of_command"
android:layout_height="wrap_content" />
</RelativeLayout>
</android.support.v7.widget.CardView>
CardView 将“包装内容”作为高度,因为权重由左侧 textview 的高度定义。 谢谢你的帮助
【问题讨论】:
标签: android android-recyclerview gridlayoutmanager