xml – Android ConstraintLayout app:layout_constraintDimensionRatio problem


[Environment]
Android Studio 4.2.2
Grade 6.7.1

[build.gradle(app)]
Implementation ‘com.google.android.material:material:1.3.0’
Implementation ‘androidx.constraintlayout:constraintlayout:2.0.4’

[Problem]
app:layout_constrainDimensionRatio, which used to work 1 to 2 weeks ago, is not working properly
I recently updated Android Studio to 4.2.2 but I’m not sure if that’s the reason

[xml]

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/cl_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#FFFFFF">>

    <FrameLayout
        android:id="@+id/fl_deleteCheck"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="8dp"
        android:visibility="visible"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:visibility="visible">

        <ImageView
            android:id="@+id/iv_deleteCheck"
            android:layout_width="26dp"
            android:layout_height="26dp"
            android:background="@drawable/todo_checkbox_check"
            android:clickable="true"
            android:src="@drawable/ic_checkbox" />

    </FrameLayout>

    <LinearLayout
        android:id="@+id/iv_chat_channel"
        android:layout_width="0dp"
        android:layout_height="60dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:layout_marginBottom="16dp"
        android:orientation="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintDimensionRatio="10:12"
        app:layout_constraintEnd_toStartOf="@+id/tv_text"
        app:layout_constraintStart_toEndOf="@+id/fl_deleteCheck"
        app:layout_constraintTop_toTopOf="parent"
        tools:visibility="visible">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/cl_profile_image_container_1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:visibility="gone"
            tools:background="@color/color_border_gray">

            <ImageView
                android:id="@+id/iv_profile_1"
                android:layout_width="1dp"
                android:layout_height="2dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintDimensionRatio="1:1"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                tools:srcCompat="@tools:sample/avatars" />
        </androidx.constraintlayout.widget.ConstraintLayout>

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/cl_profile_image_container_2"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <androidx.constraintlayout.widget.Guideline
                android:id="@+id/guideline_top"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                app:layout_constraintGuide_end="48dp" />

            <androidx.constraintlayout.widget.Guideline
                android:id="@+id/guideline_bottom"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                app:layout_constraintGuide_begin="48dp" />

            <ImageView
                android:id="@+id/iv_profile_2"
                android:layout_width="37dp"
                android:layout_height="36dp"
                app:layout_constraintBottom_toBottomOf="@id/guideline_bottom"
                app:layout_constraintDimensionRatio="1:1"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                tools:srcCompat="@tools:sample/avatars" />

            <ImageView
                android:id="@+id/iv_profile_3"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:background="@drawable/background_circle"
                android:backgroundTint="@color/color_white"
                android:padding="1dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintDimensionRatio="1:1"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toTopOf="@id/guideline_top"
                tools:srcCompat="@tools:sample/avatars"

                />

            <TextView
                android:id="@+id/tv_users_count"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:textColor="@color/color_white"
                app:layout_constraintBottom_toBottomOf="@+id/iv_profile_3"
                app:layout_constraintEnd_toEndOf="@+id/iv_profile_3"
                app:layout_constraintStart_toStartOf="@+id/iv_profile_3"
                app:layout_constraintTop_toTopOf="@+id/iv_profile_3"
                tools:text="+4" />

        </androidx.constraintlayout.widget.ConstraintLayout>

    </LinearLayout>

    <TextView
        android:id="@+id/tv_text"
        android:layout_width="0dp"
        android:layout_height="50dp"
        android:layout_marginStart="16dp"
        android:text="text-text"
        app:layout_constraintBottom_toBottomOf="@+id/iv_chat_channel"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/iv_chat_channel"
        app:layout_constraintTop_toTopOf="@+id/iv_chat_channel"/>

</androidx.constraintlayout.widget.ConstraintLayout>

iv_chat_channel width 0dp . result in

However, adding the below code to iv_chat_channel works fine

app:layout_constraintEnd_toStartOf="@+id/tv_text"

or set the height of cl_container to match_parent and the ratio will work

What changes have been made recently?



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *