Маленькое обновление для ConstraintLayout для androidx.
Включают эту строку в Ваш build.gradle:
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
я хотел получить RecycleView с GridLayoutManager с квадратом CardViews, и я использовал такое расположение для объектов:
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
>
<androidx.cardview.widget.CardView
android:id="@+id/cardView"
android:layout_width="0dp"
android:layout_height="0dp"
card_view:cardElevation="4dp"
app:layout_constraintDimensionRatio="H,1:1"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
>
На ConstraintLayout
На дочернем узле, в моем ограничивающем размере случая CardView
Посмотрите некоторые подробные объяснения на удаленный .