【发布时间】:2021-09-24 22:34:45
【问题描述】:
这个想法是让垂直链在项目之间具有不同的空间。更清楚地说,这里是 LinearLayout 所需行为的示例。
<?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="300dp"
android:background="@android:color/darker_gray"
android:orientation="vertical">
<View
android:id="@+id/space1"
android:layout_width="match_parent"
android:layout_weight="2"
android:layout_height="0dp" />
<View
android:id="@+id/contentView1"
android:layout_width="match_parent"
android:layout_weight="0"
android:layout_height="70dp"
android:background="@android:color/black" />
<View
android:id="@+id/space2"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp" />
<View
android:id="@+id/contentView2"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_weight="0"
android:background="@android:color/black" />
<View
android:id="@+id/space3"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp" />
</LinearLayout>
这里 layout_weight="0" 使内容视图包裹其高度。 layout_weight="1" 和 layout_weight="2" 使视图填充可用空间与其权重成正比。如果内容视图变大,空间就会变小(如果没有空间,就没有空间)。
由于目标 UI 比垂直堆栈更复杂,我想使用 ConstraintLayout 而不是 LinearLayout。但我没有看到设置链空间百分比的方法。
感谢您的建议。
【问题讨论】:
标签: android android-constraintlayout constraint-layout-chains