【问题标题】:Align LinearLayout over LinearLayout inside a RelativeLayout在 RelativeLayout 内将 LinearLayout 与 LinearLayout 对齐
【发布时间】: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


    【解决方案1】:

    我设法为我的问题找到了解决方案。 我用 FrameLayout 更改了第一个 LinearLayout,一切正常。请记住,第二个 LinearLayout 必须留在 FrameLayout 之下。干杯!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-13
      • 1970-01-01
      • 2013-12-26
      • 2015-12-27
      • 2015-06-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多