ConstraintLayout约束布局的layout_constraintDimensionRatio 设置说明:
举例:
被除数÷除数=商
1//宽高都写0dp,根据 layout_constraintLeft_toLeftOf,layout_constraintRight_toRightOf等属性判断出哪个是固定的,然后根据下面2,3 来判断规则
android:layout_width=“0dp”
android:layout_height=“0dp”
app:layout_constraintDimensionRatio=“w,2:1”
2//高度可变,写明的h或w就是比例2:1的除数1
android:layout_width=“100dp”
android:layout_height=“0dp”
app:layout_constraintDimensionRatio=“h,2:1” //相当于不写h
高度可变,写明的h作为除数,
w/h=2:1->w=100dp->100/h=2:1->h=50dp
高度可变,即2:1是宽:高; 2:1=100:h ,h=50dp
android:layout_width=“100dp”
android:layout_height=“0dp”
app:layout_constraintDimensionRatio=“w,2:1”
写明的w作为除数,
h/w=2:1->w=100dp->h/100=2:1->h=200dp
高度可变,即2:1是高:宽; h/100=2:1 ,h=200dp
3//宽度可变,写明的h或w就是比例2:1的被除数2
android:layout_width=“0dp”
android:layout_height=“100dp”
app:layout_constraintDimensionRatio=“h,2:1”
上述写明的h作为被除数,而h=100dp,求宽
h/w=2:1->100/w=2:1->w=50dp
宽度可变,即2:1是高:宽; 100/w=2:1 w=50dp
android:layout_width=“0dp”
android:layout_height=“100dp”
app:layout_constraintDimensionRatio=“w,2:1”
//宽不固定,写(w,2:1)相当于不写w的(2:1)
上述写明的w作为被除数,w/h=2:1,而h=100dp 求宽
w/h=2:1->w/100=2:1->w=200dp
宽度可变,即2:1是宽:高; w/100=2:1 w=200dp
//总结:
高度可变,h或w就是比例2:1的除数1,不写相当于写h
宽度可变,h或w就是比例2:1的被除数2,不写相当于写w