layout_weight=\"1\"

后端 (27) 2023-11-27 18:12

Hi,大家好,我是编程小6,很荣幸遇见你,我把这些年在开发过程中遇到的问题或想法写出来,今天说一说layout_weight=\"1\",希望能够帮助你!!!。

1.用linearlayout线性布局:

android:layout_height="0dp" <!-- 高度设为0dp -->

android:layout_weight="1" <!--layout_weight=1,确保底部的LinearLayout到底部 -->

2. 用RelativeLayout相对布局:


android:layout_alignParentBottom="true" <!-- 设置底部对齐,这个属性上级是RelativeLayout -->

线性布局举例如下:

<LinearLayout

android:layout_width="match_parent"
android:layout_height="match_parent"

android:orientation="vertical">

<LinearLayout

android:id="@+id/content"

android:layout_width="match_parent"

android:layout_height="0dp" <!-- 设置为0dp>

android:layout_weight="1" <!-- 设置layout_weight=1>

android:orientation="vertical">

</LinearLayout>

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:gravity="bottom"

android:orientation="vertical">

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:focusable="false" />

</LinearLayout>

</LinearLayout>

layout_weight=\"1\"_https://bianchenghao6.com/blog_后端_第1张

今天的分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。