【发布时间】:2023-03-18 14:48:02
【问题描述】:
我很难理解如何在 xml 文件中逐层对齐。 我搜索了解决方案,但找不到适合我需要的解决方案。
我在一个 RelativeLayout 中有两个 LinearLayout。第一个 LinearLayout 包含一个 RecycleView/ScrollView,第二个 LinearLayout 包含一些按钮。
我想将第二个 LinearLayout 设置在第一个 LinearLayout 之上,但在 RelativeLayout 的底部。见下图。
这是我测试的(它将扩展第一个布局并隐藏第二个)。
<RelativeLayout 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">
<LinearLayout
android:id="@+id/first"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<LinearLayout
android:id="@+id/second"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="@+id/first"
android:layout_alignParentBottom="true"
app:layout_gravity="bottom">
</LinearLayout>
</RelativeLayout>
您知道如何实现这一目标吗?
PS。我不想使用 BottomNavigationView 而不是第二个 LinearLayout。
【问题讨论】:
标签: android-layout layout alignment android-linearlayout android-relativelayout