같은 크기의 4 개의 버튼이있는 LinearLayout
의 가로를 ConstraintLayout
으로 변환하려고합니다. 문제는 하나 이상의 버튼을 LinearLayout
에서 android:visibility="gone"
으로 설정하면 나머지 버튼이 전체 공간을 차지하도록 크기가 조정되고 (모두 동일한 크기 임) ConstraintLayout
버튼은 제거되지만 여전히 공간을 차지합니다.LinearLayout을 ConstraintLayout 문제로 변환
편집 : 앱 상태에 따르면 다른 버튼이 표시됩니다.
ConstraintLayout
이 LinearLayout
처럼 동작하도록 변경하려면 무엇이 필요합니까?
편집 : ConstraintLayout (제약 조건 참조)에서 실수를 발견하여 이미지와 이미지 (문제는 여전히 존재 함)를 발견했습니다.
LinearLayout
XML :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<Button
android:id="@+id/b1"
android:text="B1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="50"
/>
<Button
android:id="@+id/b2"
android:text="B2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="50"
android:visibility="gone"
/>
<Button
android:id="@+id/b3"
android:text="B3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="50"
/>
<Button
android:id="@+id/b4"
android:text="B4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="50"
/>
</LinearLayout>
편집 :ConstraintLayout
XML :
<?xml version="1.0" encoding="utf-8"?>
<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="match_parent">
<Button
android:id="@+id/b1"
android:text="B1"
android:layout_width="0px"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/b2"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHorizontal_weight="1"
/>
<Button
android:id="@+id/b2"
android:text="B2"
android:layout_width="0px"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintLeft_toRightOf="@+id/b1"
app:layout_constraintRight_toLeftOf="@+id/b3"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHorizontal_weight="1"
/>
<Button
android:id="@+id/b3"
android:text="B3"
android:layout_width="0px"
android:layout_height="wrap_content"
app:layout_constraintLeft_toRightOf="@+id/b2"
app:layout_constraintRight_toLeftOf="@+id/b4"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHorizontal_weight="1"
android:layout_marginTop="0dp"/>
<Button
android:id="@+id/b4"
android:text="B4"
android:layout_width="0px"
android:layout_height="wrap_content"
app:layout_constraintLeft_toRightOf="@+id/b3"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHorizontal_weight="1"
/>
</android.support.constraint.ConstraintLayout>
왜 제대로 작동하는지 선형 레이아웃을 바꾸시겠습니까? 천천히? 그것은 많은 기억을 먹는가? – pskink
복잡한 레이아웃 구조가 있으므로 제약 레이아웃으로 변환 중입니다. 이것은 내가 변환 할 수 없었던 한 부분입니다. – Hanan
선형 레이아웃을 구속 레이아웃에 포함시킬 수는 있지만이를 피하고 싶습니다 (구속 조건 레이아웃의 목적은 깊은 레이아웃 계층을 제거하는 것입니다). – Hanan