Android 如何制作项目';GridLayoutManager中的高度是否相对于其他项目进行调整?
我有一个具有两种不同类型视图的RecyclerAdapter和一个具有15列的GridLayoutManager。在第一行中,有一个type1视图使用9个网格,然后是两个type2视图,每个视图使用3个网格。在第二行中,我有五个类型为2的视图,每个视图使用3个网格;模式从那里重复 问题是:如果一行将type1的视图与type2的视图组合在一起,type1的视图将以更大的高度增长,而type2的视图则在底部留有一个空间。我想根据其他视图的高度调整第一个视图的高度。我不能使用固定高度,第一个视图应该相对其他视图进行调整 类型1布局:Android 如何制作项目';GridLayoutManager中的高度是否相对于其他项目进行调整?,android,android-recyclerview,android-constraintlayout,gridlayoutmanager,Android,Android Recyclerview,Android Constraintlayout,Gridlayoutmanager,我有一个具有两种不同类型视图的RecyclerAdapter和一个具有15列的GridLayoutManager。在第一行中,有一个type1视图使用9个网格,然后是两个type2视图,每个视图使用3个网格。在第二行中,我有五个类型为2的视图,每个视图使用3个网格;模式从那里重复 问题是:如果一行将type1的视图与type2的视图组合在一起,type1的视图将以更大的高度增长,而type2的视图则在底部留有一个空间。我想根据其他视图的高度调整第一个视图的高度。我不能使用固定高度,第一个视图应
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/color_list_item_subtitle">
<ImageView
android:id="@+id/cover"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintWidth_default="percent"
app:layout_constraintWidth_percent="0.5"
android:adjustViewBounds="true"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintLeft_toRightOf="@id/cover"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent">
<TextView
android:id="@+id/title"
style="title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/category_title"
android:textColor="@color/white"/>
<TextView
android:id="@+id/subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/text_list_item_subtitle"
android:textColor="@color/white"/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
类型2布局:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/cover"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/cover"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:textSize="@dimen/category_title"
android:textColor="@color/white"
android:maxLines="1"
android:ellipsize="end"/>
</androidx.constraintlayout.widget.ConstraintLayout>
我将我的type1布局更改为这个布局,现在它的伸展高度仅与它的同级一样高
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/recommendations_tracks_item_background">
<ImageView
android:id="@+id/cover"
android:layout_width="wrap_content"
android:layout_height="0dp"
app:layout_constraintHeight_default="percent"
app:layout_constraintHeight_percent="1"
android:adjustViewBounds="true"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintLeft_toRightOf="@id/cover"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent">
<TextView
android:id="@+id/title"
style="title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/category_title"
android:textColor="@color/white"
android:gravity="center"
android:maxLines="1"
android:ellipsize="end"/>
<TextView
android:id="@+id/subtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/text_list_item_subtitle"
android:textColor="@color/white"
android:gravity="center"
android:maxLines="1"
android:ellipsize="end"/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>