【发布时间】:2018-02-28 18:40:41
【问题描述】:
尝试使用 ConstraintLayout 为设置页面创建一个非常简单的布局。 左侧的简单文本视图位于另一个下方,右侧的切换到中心。 我的布局适用于较新的设备,但一旦我切换到 Nexus 4 或更旧的设备,开关就会低于/从视图中消失。
这是我的布局代码,
<android.support.constraint.ConstraintLayout
android:id="@+id/locationLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="parent">
<TextView
android:id="@+id/locationTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/location_title"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="@id/guidelineLocationLayout"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:textSize="16sp"/>
<TextView
android:id="@+id/locationDescription"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/location_description"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/locationTitle"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="@id/locationTitle"
app:layout_constraintRight_toLeftOf="@id/guidelineLocationLayout"
android:textSize="12sp"
/>
<Switch
android:id="@+id/locationPermissionSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@id/guidelineLocationLayout"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="parent"/>
<View
android:id="@+id/viewLocationLayout"
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#d6d6d6"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/locationDescription"/>
<android.support.constraint.Guideline
android:id="@+id/guidelineLocationLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_end="48dp" />
</android.support.constraint.ConstraintLayout>
以下是 Pixel 2XL 的约束情况,
这是它们在较小设备上的外观,
我在长描述中使用了 0dp 宽度并定义了左右约束,我还能做什么?
【问题讨论】:
标签: android android-layout android-constraintlayout