我試圖設置自定義視圖的高度,以便它等於它的父項。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