android studio中让一个控件按钮居于底部的几种方法,以及在RelativeLayout中的左中右

    技术2025-04-09  14

    让一个控件按钮居于底部

    1.采用linearlayout布局: android:layout_height=“0dp” android:layout_weight=“1”

    <TextView android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="1" android:orientation="vertical" android:background="@drawable/gray" ></TextView>

    2. 采用relativelayout布局:

    android:layout_alignParentBottom=“true”

    <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:layout_width="match_parent" android:layout_height="500dp" android:background="@drawable/gray" android:layout_margin="20dp" android:layout_alignParentBottom="true" ></TextView> </RelativeLayout>

    RelativeLayout相对布局(控件相对父控件摆放-左上、右上、中间、左下、右下

    <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:text="左上角" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:backgroundTintMode="multiply" android:layout_alignParentRight="true" android:text="右上角" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="中间" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:text="左下角"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:text="右下角" />
    Processed: 0.009, SQL: 9