如何在 ConstraintLayout Android Studio 中创建重叠链
How to Create an overlap chain in ConstraintLayout Android Studio
我想创建一个重叠链,它比其他元素保持所需的边距,并且它们可能有更多的元素彼此相邻。像这样:
这可以使用 Guidelines
来实现。尝试这样的事情:
<?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">
<View
android:id="@+id/view_1"
android:layout_width="200dp"
android:layout_height="200dp"
android:background="#f00"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.constraint.Guideline
android:id="@+id/guideline_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.26" />
<View
android:id="@+id/view_2"
android:layout_width="200dp"
android:layout_height="200dp"
android:background="#0f0"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/guideline_1"
app:layout_constraintTop_toTopOf="parent" />
<android.support.constraint.Guideline
android:id="@+id/guideline_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.52" />
<View
android:id="@+id/view_3"
android:layout_width="200dp"
android:layout_height="200dp"
android:background="#00f"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/guideline_2"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
我想创建一个重叠链,它比其他元素保持所需的边距,并且它们可能有更多的元素彼此相邻。像这样:
这可以使用 Guidelines
来实现。尝试这样的事情:
<?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">
<View
android:id="@+id/view_1"
android:layout_width="200dp"
android:layout_height="200dp"
android:background="#f00"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.constraint.Guideline
android:id="@+id/guideline_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.26" />
<View
android:id="@+id/view_2"
android:layout_width="200dp"
android:layout_height="200dp"
android:background="#0f0"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/guideline_1"
app:layout_constraintTop_toTopOf="parent" />
<android.support.constraint.Guideline
android:id="@+id/guideline_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.52" />
<View
android:id="@+id/view_3"
android:layout_width="200dp"
android:layout_height="200dp"
android:background="#00f"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/guideline_2"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>