个人理解: 相对布局:以一个对象为参照,另一个对象添加到这个对象的上,下、左、右, 左上、左下、右上、右下等位置
宽度包含内容
android:layout_width
wrap_content 与内容宽度相同
fill_parent 与父对象宽度相同
android:layout_below="@+id/ok"
对象位于id为ok对象的下面
android:layout_toLeftOf="@id/ok"
对象位于ok对象的左边
android:layout_centerHorizontal="true"
水平居中,个人认为就是在容器中间对齐
android:layout_alignLeft="@+id/ok"
与id为ok的对象左对齐
padding表示填充,margin表示边距
可通过android:padding属性进行设置,4个方向的边距属性为android:paddingLeft, android:paddingRight, android:paddingTop, and android:paddingBottom.
结论:
*android:layout_marginBottom
*android:layout_marginLeft
*android:layout_marginRight
*android:layout_marginTop
上面几个属性的值是根据下面的相对位置的对象的值来做计算的,如果没有相对的对象就以总体布局来计算
*android:layout_below
*android:layout_above
*android:layout_toLeftOf
*android:layout_toRightOf
*android:layout_alignTop
*android:layout_centerHrizontal //是否支持横屏或竖屏
*android:layout_centerVertical //这个根据单词的意思:中心垂直
*android:layout_centerInparent //
android:layout_centerInParent="true"//居中在父对象
android:layout_centerInParent="false" ... 浏览器不支持多窗口显示,意思就是说所有页面在单一窗口打开,这样避免了页面布局控制显示问题
下面的相对于父的相对位置
*android:layout_alignParentBottom
*android:layout_alignParentLeft
*android:layout_alignParentRight
*android:layout_alignParentTop
*android:layout_alignWithParentIfMissing
实例代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> <Button android:id="@+id/testBtn1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/textView1" android:layout_centerHorizontal="false" android:layout_marginTop="46dp" android:text="Button" /> <Button android:id="@+id/activity1_btn2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/testBtn1" android:layout_below="@+id/testBtn1" android:layout_marginTop="20dp" android:text="RadioGroupStudy" /> <Button android:id="@+id/testBtn4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/activity1_btn2" android:layout_centerHorizontal="true" android:layout_marginTop="20dp" android:text="@string/linerlayout_test" /> </RelativeLayout>
相关推荐
Android 开发入门 对 RelativeLayout的基本属性的讲解和用法 ,更容易的帮你理解和使用
Android布局入门,LinearLayout和RelativeLayout的理解和应用
自定义RelativeLayout圆角图片背景,自定义属性 背景 圆角半径
介绍一下RelativeLayout的一些属性,针对于刚学习android开发的朋友
Android 相对布局 RelativeLayout 属性
Android RelativeLayout 的翻译应用。希望能给大家帮助
总结android中相对布局RelativeLayout的所有属性及使用方法。适合初级程序员
RelativeLayout 上 下 中 左 右布局 demo
介绍了android 中 RelativeLayout 下的各种属性。linux下打开.
LinearLayout与RelativeLayout混合用
Android相对布局RelativeLayout的基本用法,相对布局是最实用的布局。
android实现自定义RelativeLayout可拖动、缩放、旋转TextView
Android 布局属性 RelativeLayout 详解 Android 布局属性 RelativeLayout 是 Android 中常用的布局方式之一,通过它可以实现复杂的界面布局。下面是 RelativeLayout 的主要属性详解: 第一类:属性值为 true 或 ...
相对布局我最新喜欢的布局,也是game开发,照相机以及增钱现实中最常用的布局!
安卓动态控制RelativeLayout的组件
RelativeLayout android 布局练习
RelativeLayout点击效果,背景色的变化,通过两种方法:1. 直接用图片资源; 2. 用color资源
像 RelativeLayout 一样的 RadioGroup
DragView 可拖拽的view,继承自RelativeLayout
【Android开发学习25】界面布局之相对布局RelativeLayout(代码)