我试图设置自定义视图的高度,以便它等于它的父项。ConstraintLayout,layout_height中的0dp,但视图向左移动?
下面的布局并没有正确设置自定义视图的高度,以其父(我已记录到OnMeasure调用)。但是,限制布局无法正确定位视图。只要layout_height设置为0dp,视图就会向左移动(包括在android studio设计器中)。
<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。
我在做什么错了?
你已将它设置为应用程序:layout_constraintRight_toLeftOf你可能表示应用程序:layout_constraintRight_toRightOf – MidasLefko
看,这是一个愚蠢的错误。 –
添加它作为答案,所以我可以投票:) BenP试图得到的观点:D – Softlion