Android 相对布局 : how to put a view below another view when both aren't at the same container

标签 android android-relativelayout

我在 LinearLayout 中有一个 TitleBar(#lotTopTitleBar),LinearLayout 将全屏显示,现在,我想显示一个 View(#lotFloatView ) 引用下面的 TitleBar,但两个 View 不在同一级别容器中,因此 layout_below 不起作用,如果有人知道,请帮助我进行更改。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

    <LinearLayout android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:orientation="vertical">

        <LinearLayout android:id="@+id/lotTopTitleBar"
                      android:layout_width="match_parent"
                      android:layout_height="50dp">
        </LinearLayout>

        <LinearLayout android:layout_width="match_parent"
                      android:layout_height="0dp"
                      android:layout_weight="1">
        </LinearLayout>

        <LinearLayout android:layout_width="match_parent"
                      android:layout_height="50dp">
        </LinearLayout>

    </LinearLayout>

    <LinearLayout android:id="@+id/lotFloatView"
                  android:layout_width="120dp"
                  android:layout_height="wrap_content"
                  android:layout_below="@id/lotTopTitleBar">
        <Button android:layout_width="match_parent"
                android:layout_height="60dp"
                android:background="@null" />
        <Button android:layout_width="match_parent"
                android:layout_height="60dp"
                android:background="@null" />
    </LinearLayout>

</RelativeLayout>

最佳答案

我认为您可以通过使用相对布局而不是线性布局来实现这一点。我没有测试过它,但它应该可以工作。

    <RelativeLayout android:layout_width="match_parent"
              android:layout_height="match_parent"
              >

       <LinearLayout android:id="@+id/lotTopTitleBar"
                  android:layout_width="match_parent"
                  android:layout_height="50dp">
    </LinearLayout>
    <LinearLayout android:id="@+id/lotFloatView"
              android:layout_width="120dp"
              android:layout_height="wrap_content"
              android:layout_below="@id/lotTopTitleBar">
    <Button android:layout_width="match_parent"
            android:layout_height="60dp"
            android:background="@null" />
    <Button android:layout_width="match_parent"
            android:layout_height="60dp"
            android:background="@null" />
</LinearLayout>

    <LinearLayout android:layout_width="match_parent"
                  android:layout_height="0dp"
                  android:layout_below="@id/lotTopTitleBar"
                  android:id="@+id/lotLL"
                  android:layout_weight="1">
    </LinearLayout>

    <LinearLayout android:layout_width="match_parent"
                  android:layout_below="@id/lotLL"
                  android:layout_height="50dp">
    </LinearLayout>

</RelativeLayout >

编辑

    <LinearLayout android:layout_width="match_parent"
                  android:layout_below="@id/lotLL"
                  android:layout_alignParentBottom="true"
                  android:id="@+id/lotLastLL"
                  android:layout_height="50dp">
    </LinearLayout>

    <LinearLayout android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:layout_below="@id/lotTopTitleBar"
                  android:layout_above="@id/lotLastLL"
                  android:id="@+id/lotLL"
                  >
    </LinearLayout>

关于Android 相对布局 : how to put a view below another view when both aren't at the same container,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17646227/

相关文章:

android - RelativeLayout 可滚动

android - 将图像从 ImageView 设置为 Dialog

java - 为什么日历值不同?

Android:如何在同一部手机中同时保留我的应用程序的签名版和调试版?

android - 如何将 View 粘贴在屏幕底部以便上面的部分可以移动?

android - FrameLayout to RelativeLayout ClassCastException 即使没有使用 FrameLayout

android - 如何在随机屏幕位置显示按钮

android - 如何从 Android 中的 Google map 中删除特定标记

android - 如何将 LinearLayout 放置在另一个 RelativeLayout 内的 LinearLayout 下方?

android - 处理 RelativeLayout 的更好方法