【发布时间】:2020-02-05 03:13:08
【问题描述】:
我在一个相对布局中直接有两个线性布局。
我希望第一个 LinearLayout 占据 75% 的高度,接下来是 25%。我如何做到这一点?
例如
<RelativeLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:weightSum="100"
android:id="@+id/contentMainLayout">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="75"
android:id="@+id/linearLayout1">
<ScrollView
android:id="@+id/mainScrollView"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:id="@+id/mainScrollLL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="25"
android:layout_marginBottom="20dp"
android:layout_below="@+id/mainScrollParentLL"
android:orientation="horizontal">
<Button
android:id="@+id/startTrade"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start Trade"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Stop Trade"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>
</RelativeLayout>
我希望 linearLayout1 使用 75% 的可用高度,而 linearLayout2 使用 25%。
没有为LinearLayout定义layout_weight,所以显然它不起作用。
有什么方法可以实现吗?
这似乎是一个很常见的场景,所以我几乎可以肯定这个问题之前已经被问过。
但我似乎没有找到它。
如果这是重复的问题,请指出我原来的问题,我会关闭它。
【问题讨论】:
标签: android android-linearlayout