我在 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/