4
以下のビューは正方形である必要があります。私はまた、一定の大きさに制限されたビューを望んでいます。何らかの理由で、ConstraintLayoutは、同じ要素のdimensionRatioと組み合わせて使用すると、max width/heightプロパティを無視しています。ConstraintLayoutはDimensionRatioと組み合わせて最大幅/高さを考慮しません
<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"/>
現時点では、次のようにビューをコンテナに入れて回避策を使用しています。しかし、私はむしろ私のレイアウト階層を可能な限りフラットにしておきたいと思います。
<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"
/>
これは制約のレイアウトで、最大幅と高さを寸法比と組み合わせて使用できないという制約ですか?
私はConstraintLayout v1.0.2を使用しています。
私のために働いた!ありがとう:) – Jono0