ConstraintLayout,layout_height 中的 0dp,但视图移到最左边?
ConstraintLayout, 0dp in layout_height, but view is moved far left?
我正在尝试设置自定义视图的高度,使其与其父视图相同。
以下布局正确地将自定义视图的高度设置为其父视图(我已经记录了对 OnMeasure 的调用)。但是约束布局无法正确定位视图。一旦 layout_height 设置为 0dp,视图就会向左移动(包括在 android 工作室设计器中)。
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
/>
<View
android:background="#ff0000"
app:layout_constraintRight_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_width="50dp"
android:layout_height="10dp"
/>
</android.support.constraint.ConstraintLayout>
如果我将此高度设置为 10dp,则会出现视图。
ContraintLayout 似乎隐藏了视图,因为它的一个属性中有 0dp。这怎么可能?
doc 说明应该改为 MATCH_CONSTRAINT。
我做错了什么?
您的视图显示在屏幕外,因为您指定了 constraintRight_toLeftOf
而不是 constraintRight_toRightOf
。
你有 app:layout_constraintRight_toLeftOf。你可能是说 app:layout_constraintRight_toRightOf
我正在尝试设置自定义视图的高度,使其与其父视图相同。
以下布局正确地将自定义视图的高度设置为其父视图(我已经记录了对 OnMeasure 的调用)。但是约束布局无法正确定位视图。一旦 layout_height 设置为 0dp,视图就会向左移动(包括在 android 工作室设计器中)。
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
/>
<View
android:background="#ff0000"
app:layout_constraintRight_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_width="50dp"
android:layout_height="10dp"
/>
</android.support.constraint.ConstraintLayout>
如果我将此高度设置为 10dp,则会出现视图。
ContraintLayout 似乎隐藏了视图,因为它的一个属性中有 0dp。这怎么可能?
doc 说明应该改为 MATCH_CONSTRAINT。
我做错了什么?
您的视图显示在屏幕外,因为您指定了 constraintRight_toLeftOf
而不是 constraintRight_toRightOf
。
你有 app:layout_constraintRight_toLeftOf。你可能是说 app:layout_constraintRight_toRightOf