我使用ConstraintLayout在那裏我將顯示如下ConstraintLayout,當約束依賴視消失,佈局視圖古怪行爲
我想隱藏First
(採用了),並視圖我希望如下(這裏可以將ElasticBody上伸展使用了原來First
視圖空間爲好。
然而,磨片ñ我實際設置First
到gone
,我的看法如下(所有圖像來自Android Studio Design視圖)。我的Elastic Body
也不見了,高度奇怪地擴大了。
我的佈局代碼如下
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<TextView
android:id="@+id/txt_first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#0ff"
android:text="First"
android:visibility="gone"
android:textSize="26sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/txt_body"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/txt_body"
android:layout_width="0dp"
android:background="#f0f"
android:layout_height="wrap_content"
android:text="Elastic Body"
android:textSize="26sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/txt_tail"
app:layout_constraintStart_toEndOf="@+id/txt_first"
app:layout_constraintTop_toBTopOf="parent" />
<TextView
android:id="@+id/txt_tail"
android:background="#ff0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tail"
android:textSize="26sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/txt_body"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
(請注意,如果您刪除gone
,你會得到的第一個圖像視圖)。 這是爲什麼呢?我該如何修復它,當我的First
不見了,我可以將Elastic Body
伸展出來嗎?
p/s:我知道如何在LinearLayout和RelativeLayout中做到這一點......但不知道這是否是對ConstraintLayout的限制?
感謝。有趣的是,從'tail'移除'app:layout_constraintStart_toEndOf =「@ + id/txt_body」'有助於。 Upvote你的答案。你能否闡述背後的邏輯?謝謝! (不知道誰不投票,他們至少應該給出一個理由......) – Elye
想了一會兒,我想我明白了邏輯。我將你的答案作爲答案。謝謝! (如果你認爲有助於他人,請加我的問題) – Elye
請給我投票的理由。 –