ConstraintLayout does not consider maximum width / height in combination with DimensionRatio

The view below should be square. I also want the view to be limited to a specific size. One way or another, ConstraintLayout ignores the max width / height property when used in combination with dimensionRatio on the same element.

<android.support.constraint.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:layout_width="match_parent"
android:layout_height="match_parent">
    <View 
       android:layout_width="0dp"
       android:layout_height="0dp"
       app:layout_constraintTop_toTopOf="@+id/guideline_top"
       app:layout_constraintDimensionRatio="1:1"
       app:layout_constraintLeft_toLeftOf="@+id/guideline_left"
       app:layout_constraintRight_toRightOf="@+id/guideline_right"
       app:layout_constraintBottom_toBottomOf="@+id/guideline_bottom" 
       app:layout_constraintWidth_max="100dp"
       app:layout_constraintHeight_max="100dp"/>

I am currently using a workaround by placing the View in a container, as shown below. But I would prefer my layout hierarchy to be as flat as possible.

<android.support.constraint.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:layout_width="match_parent"
android:layout_height="match_parent">
    <android.support.constraint.ConstraintLayout 
          android:layout_width="0dp"
          android:layout_height="0dp"
          app:layout_constraintTop_toTopOf="@+id/guideline_top"
          app:layout_constraintLeft_toLeftOf="@+id/guideline_left"
          app:layout_constraintRight_toRightOf="@+id/guideline_right"
          app:layout_constraintBottom_toBottomOf="@+id/guideline_bottom"
          app:layout_constraintWidth_max="100dp"
          app:layout_constraintHeight_max="100dp"> 
             <View 
                android:layout_width="0dp"
                android:layout_height="0dp"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintDimensionRatio="1:1"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintBottom_toBottomOf="parent" 
                />

Is this a limitation in constraintlayout that you cannot use maximum width / height combined with aspect ratio?

I am using ConstraintLayout v1.0.2.

+4
source share
1 answer

`app:layout_constraintDimensionRatio="H,1:1"` 

`app:layout_constraintDimensionRatio="W,1:1"`

, ConstraintLayout . . "" .

+5

Source: https://habr.com/ru/post/1686113/


All Articles