ConstraintLayout 不遵守 max width/height 与 DimensionRatio 的结合
ConstraintLayout doesn't respect max width/height in combination with DimensionRatio
下面的视图需要是方形的。我还想将视图限制在一定大小。当 ConstraintLayout 与同一元素上的 dimensionRatio 结合使用时,ConstraintLayout 会忽略 max width/height 属性。
<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中的限制,不能将max width/height与尺寸比结合使用吗?
我正在使用 ConstraintLayout v1.0.2。
指定
`app:layout_constraintDimensionRatio="H,1:1"`
或
`app:layout_constraintDimensionRatio="W,1:1"`
这应该会导致ConstraintLayout
选择您的最大宽度和高度。请参阅文档中的 "Ratios"。
下面的视图需要是方形的。我还想将视图限制在一定大小。当 ConstraintLayout 与同一元素上的 dimensionRatio 结合使用时,ConstraintLayout 会忽略 max width/height 属性。
<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中的限制,不能将max width/height与尺寸比结合使用吗?
我正在使用 ConstraintLayout v1.0.2。
指定
`app:layout_constraintDimensionRatio="H,1:1"`
或
`app:layout_constraintDimensionRatio="W,1:1"`
这应该会导致ConstraintLayout
选择您的最大宽度和高度。请参阅文档中的 "Ratios"。