RelativeLayout相对布局

xiaoxiao2021-02-28  90

RelativeLayout相对布局

相对布局 RelativeLayout 允许子元素指定它们相对于其父元素或兄弟元素的位置,这是实际布局中最常用的布局方式之一。它灵活性大很多,当然属性也多,操作难度也大,属性之间产生冲突的的可能性也大,使用相对布局时要多做些测试。

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <!--相对布局--> <!--完成上课代码--> <!--TestSize:字体的大小 Testcolor:字体的颜色 graving:位置 --> <!--用相对布局来写上下左右--> <RelativeLayout android:layout_width="250dp" android:layout_height="250dp"> <!--左上:layout_height:左上--> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="左上" /> <!--设置二个按钮中间间隔--> <Button android:layout_width="wrap_content" android:layout_height="0dp" android:width="7dp" /> <!--右上:layout_alignParenRight:右上--> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="右上" android:layout_alignParentRight="true" /> <!--中间:layout_centerInParent--> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="中间" android:layout_centerInParent="true" /> <!--左下:layout_alignParentBotton --> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="左下" android:layout_alignParentBottom="true" /> <!-- 左下:layout_alignParenBotton 右下:layout_alignParenRight 思路:先设置一个按钮,用相对布局的layout_alignParenBotton来设置, 用按钮往左下,然后在用layout_alignParenRight来设置,按钮往左边, --> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:text="右下" /> </RelativeLayout> </RelativeLayout>

转载请注明原文地址: https://www.6miu.com/read-28744.html

最新回复(0)