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