Android基本布局-RelativeLayout
来源:互联网 发布:主持人辅助软件 编辑:程序博客网 时间:2024/06/05 00:19
相对布局可以让空间以相对位置的形式出现在布局的任意位置
控件与父布局对齐
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <Button android:id="@+id/button_1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:text="Button 1" /> <Button android:id="@+id/button_2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:text="Button 2" /> <Button android:id="@+id/button_3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="Button 3" /> <Button android:id="@+id/button_4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:text="Button 4" /> <Button android:id="@+id/button_5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:text="Button 5" /></RelativeLayout>
五个按钮分别出现在左上,右上,中间和左下,右下
注意到
android:layout_alignParentLeft="true"android:layout_alignParentTop="true"android:layout_alignParentRight="true"android:layout_centerInParent="true"android:layout_alignParentBottom="true"
表示按钮分别与父布局的左,上,右,中,下对齐
控件与控件对齐
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <Button android:id="@+id/button_1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="Button 1" /> <Button android:id="@+id/button_2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/button_1" android:layout_toLeftOf="@+id/button_1" android:text="Button 2" /> <Button android:id="@+id/button_3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/button_1" android:layout_toRightOf="@id/button_1" android:text="Button 3" /> <Button android:id="@+id/button_4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/button_1" android:layout_toLeftOf="@id/button_1" android:text="Button 4" /> <Button android:id="@+id/button_5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/button_1" android:layout_toRightOf="@id/button_1" android:text="Button 5" /></RelativeLayout>
Button2到4分别位于Button1的左上,右上,左下,右下
注意到
android:layout_centerInParent="true"android:layout_above="@+id/button_1"android:layout_toLeftOf="@+id/button_1"android:layout_toRightOf="@id/button_1"android:layout_below="@id/button_1"
button_1与父布局对齐居中显示,其他button分别与button_1对齐位于上,左,右,下
0 0
- Android基本布局-RelativeLayout
- Android相对布局RelativeLayout的基本用法
- Android 基本布局(2)FrameLayout和RelativeLayout
- 【Android】35、基本布局——RelativeLayout
- android四种基本布局之RelativeLayout
- Android 四种基本布局LinearLayout、RelativeLayout、FrameLayout、TableLayout
- Android RelativeLayout布局详解
- Android布局之RelativeLayout
- android RelativeLayout布局属性
- Android布局之RelativeLayout
- Android RelativeLayout布局属性
- Android 相对布局:RelativeLayout
- android 相对布局RelativeLayout
- android 相对布局 RelativeLayout
- android RelativeLayout布局注意
- android----relativelayout布局
- Android RelativeLayout 布局
- Android RelativeLayout布局学习
- C++模板实现堆排序
- GDOI第三轮模拟总结
- 《C++ Primer》第3章:字符串、向量和数组
- malloc和free
- Java 多线程(五)——线程通信(共享内存、管道流、wait()、notify()等)
- Android基本布局-RelativeLayout
- Java面试题全集(下)
- java线程的同步 排斥性与可见性
- MySQL经典问题
- Java时间类总结
- ckplayer实现mp4等html5支持格式视频的网页播放
- XDOJ-1201-Dogs of Qwordance Senior Backend R&D Engineers(数论)
- Java 多线程(六)——进程间通信与线程间通信
- final使用方法总结