두 개의 헤더보기, HeaderViewA
및 HeaderViewB
이 있습니다. 이러한보기에는 가시성 visible
또는 gone
의 조합이있을 수 있습니다. 제가ConstraintLayout에서 두 개의 뷰 중 가장 낮은 위치에 배치하는 방법은 무엇입니까?
BigView
필요
는 어느 HeaderViewA
/HeaderViewB
의 최저아래에 위치한다.
중첩없이 가능하면 ConstraintLayout
입니까?
두 개의 헤더보기, HeaderViewA
및 HeaderViewB
이 있습니다. 이러한보기에는 가시성 visible
또는 gone
의 조합이있을 수 있습니다. 제가ConstraintLayout에서 두 개의 뷰 중 가장 낮은 위치에 배치하는 방법은 무엇입니까?
BigView
필요
는 어느 HeaderViewA
/HeaderViewB
의 최저아래에 위치한다.
중첩없이 가능하면 ConstraintLayout
입니까?
제약 레이아웃 v1.1.0에서 소개 된 Barrier 클래스가 가능합니다.
그래서 여기가 특정 경우에 대한 해결책 :
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.eugene.test10.MainActivity">
<TextView
android:id="@+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#EEEEEE"
android:text="TEXT_VIEW_1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toLeftOf="@+id/textView2"/>
<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#DDDDDD"
android:text="TEXT_VIEW_2"
android:visibility="gone"
app:layout_constraintLeft_toRightOf="@+id/textView1"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.constraint.Barrier
android:id="@+id/labelBarrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
app:constraint_referenced_ids="textView1,textView2" />
<TextView
android:id="@+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#CCCC00"
android:text="TEXT_VIEW_3"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/labelBarrier" />
</android.support.constraint.ConstraintLayout>
이 레이아웃을 사용하는
바로 여기에 결과 : 당신은 코드 랩에이 단계별 가이드를 참조 할 수 있습니다
https://codelabs.developers.google.com/codelabs/constraint-layout/#10.
장벽을 구현하기 위해 프로젝트에서 제일 먼저 필요한 것이 있습니까? – Zerato
@Zerato 모듈의 gradle 파일에''com.android.support.constraint : constraint-layout : 1.1.0-beta3'' 의존성을 추가하고 프로젝트의 gradle 파일에 maven 저장소를 추가해야합니다. 이 GitHub 프로젝트에서 모든 의존성을 찾을 수 있습니다. https://github.com/googlecodelabs/constraint-layout –
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/header_view_a"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@android:color/holo_orange_light"
android:gravity="center"
android:text="HeaderViewA "
android:layout_marginBottom="@dimen/sixteenDP"
android:textSize="30sp"
app:layout_constraintBottom_toTopOf="@+id/guideline"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/header_view_b"
app:layout_constraintEnd_toStartOf="@+id/header_view_b"
app:layout_constraintVertical_bias="0"
app:layout_constraintWidth_default="wrap" />
<TextView
android:id="@+id/header_view_b"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:background="@android:color/holo_green_light"
android:gravity="center"
android:text="HeaderViewB"
android:textAlignment="center"
android:textSize="30sp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@id/guideline"
app:layout_constraintStart_toEndOf="@+id/header_view_a"/>
<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.4"/>
<TextView
android:id="@+id/big_view"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:background="@android:color/holo_blue_dark"
android:gravity="center"
android:text="BigView"
android:textAlignment="center"
android:textSize="@dimen/list_item_height"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/guideline"
app:layout_constraintVertical_bias="1.0"/>
</android.support.constraint.ConstraintLayout>
Watch outapp:layout_constraintWidth_default="wrap"
(폭 세트를 0dp하기)위한
app:layout_constraintVertical_bias="1.0"
에 의해 제한됩니다. 바이어스를 사용하여 BigView를 부모의 맨 아래로 가져옵니다.
나는 다른 대답을 듣고 싶지만 afaik는 불가능합니다. – F43nd1r
흥미롭지 만 XML을 통해서만 보일 수는 없습니다. 중첩 된 뷰는 필요 없지만 프로그래밍 방식의 조작에 열려 있으면 [ConstraintSet] (https://developer.android.com/reference/android/support/constraint/ConstraintSet.html)을 사용할 수 있습니다. – Cheticamp
ConstraintLayout을 거래 차단기에 중첩시키는 이유는 무엇입니까? –