Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在相对线的底部对齐线性布局_Android_Android Layout - Fatal编程技术网

Android 在相对线的底部对齐线性布局

Android 在相对线的底部对齐线性布局,android,android-layout,Android,Android Layout,我有这些嵌套的布局,我想把一个线性布局锚定到第一个RelativeLayout的底部(内部),但我不知道怎么做。有人能帮我吗?我想要这样的东西: 如果要将视图与需要使用的相对布局的底部对齐 android:layout\u alignParentBottom=“true” 在视图中,它将被固定在相对的底部,因为您的UI中也需要权重,所以这对您很有用 <LinearLayout android:layout_width="match_parent" android:layou

我有这些嵌套的布局,我想把一个线性布局锚定到第一个RelativeLayout的底部(内部),但我不知道怎么做。有人能帮我吗?我想要这样的东西:


如果要将视图与需要使用的相对布局的底部对齐
android:layout\u alignParentBottom=“true”


在视图中,它将被固定在相对的底部,因为您的UI中也需要
权重,所以这对您很有用

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:orientation="vertical"
    android:weightSum="1">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.65"
        android:background="@drawable/background_gradient">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_alignParentBottom="true"
            android:layout_height="wrap_content">

        </LinearLayout>
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.35">

    </RelativeLayout>
</LinearLayout>


使用id将线性布局与底部对齐。
获取相对布局的id,然后将线性布局与相对布局id末端的底部对齐。

要使
布局权重
正常工作,请为两个相对布局设置
android:layout\u height=“0dp”

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="1">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.65"
        android:background="@color/colorPrimary">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_alignParentBottom="true"
            android:layout_marginTop="10dp"
            android:layout_marginStart="10dp"
            android:layout_marginEnd="10dp"
            android:layout_height="match_parent"
            android:background="@color/colorAccent">

        </LinearLayout>
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.35"
        android:background="@color/colorPrimaryDark">

    </RelativeLayout>

</LinearLayout>

把10dp换成适合你的

我设置颜色只是为了区分布局

为每个视图添加id,然后解释问题。问题不清楚,我添加了一个布局应该如何的图像
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="1">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.65"
        android:background="@color/colorPrimary">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_alignParentBottom="true"
            android:layout_marginTop="10dp"
            android:layout_marginStart="10dp"
            android:layout_marginEnd="10dp"
            android:layout_height="match_parent"
            android:background="@color/colorAccent">

        </LinearLayout>
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.35"
        android:background="@color/colorPrimaryDark">

    </RelativeLayout>

</LinearLayout>