RelativeLayout是一个在相对位置上显示子View元素的VeiwGroup,一个视图的位置,可以指定为相对于兄妹的元素(比如一个给定的与孙的左边或者下边)或者心爱那个对于RelativeLayout区域的位置(比如与底部对齐,剩下的中心)
一个RelativeLayout是一个非常强大使用的为设置用户界面的布局,因为它可以消除嵌套的视图组ViewGroup,如过你发现你用了几个嵌套的LinearLayout组,你可以替换为一个单独的RelativeLayout
1、开始一个新的工程,名字叫做HelloRelativeLayout
2、打开res/layout/main.xml文件并且插入如下信息
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Type here:"
/>
<EditText
android:id="@+id/entry"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:layout_below="@id/label"
/>
<Button
android:id="@+id/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/entry"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:text="OK"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/ok"
android:layout_alignTop="@id/ok"
android:text="Cancel"
/>
</RelativeLayout>
3、注意到每一个android:layout_*属性,比如layout_below,layout_alignParentRightRight,和layout_toLeftOf,当用一个RelativeLayout的时候,你可以用这些属性来描述你想要的每个视图View的位置,每一个这些属性都定义一个不懂种类的相对位置,一些属性用到同级视图的资源ID来定义自己的相对位置。比如最后一个Button是被定义到位于被定义ID为ok的视图的左边和顶部对齐,
所有的layout布局属性都被定义在RelativeLayout.LayoutParams中
4、现在打开HelloLinearLayout.java并且确定它已经在onCreate()方法中加载了res/layout/main.xml布局文件
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
5、你可以看到如下的布局
- 大小: 10.3 KB
分享到:
相关推荐
•Android---UI篇---RelativeLayout(相对布局) • •Android---UI篇---GridView(网格布局) • •Android---UI篇---Gallery(画廊视图) • •Android---UI篇---Spinner(下拉列表) • •Android---UI篇---...
19Android-02-03-LineaLayout-relativeLayout.mp4
Android 相对布局 RelativeLayout 属性
Android相对布局RelativeLayout的基本用法,相对布局是最实用的布局。
【Android开发学习25】界面布局之相对布局RelativeLayout(代码)
RelativeLayout是相对布局控件:以控件之间相对位置或相对父容器位置进行排列,下面通过本文给大家介绍Android布局之RelativeLayout相对布局,涉及到android relativelayout相对布局相关知识,对android ...
像 RelativeLayout 一样的 RadioGroup
这个程序写了对相对布局和绝对布局的例子,帮助大家理解两者的使用和区别。
总结android中相对布局RelativeLayout的所有属性及使用方法。适合初级程序员
android布局属性RelativeLayout详解.
相对布局我最新喜欢的布局,也是game开发,照相机以及增钱现实中最常用的布局!
Android应用开发
android实现自定义RelativeLayout可拖动、缩放、旋转TextView
Android中使用RelativeLayout布局完成的登录练习题要求说明.pdf 学习资料 复习资料 教学资源
Android移动应用开发相对布局RelativeLayout的特点.pdf 学习资料 复习资料 教学资源
DragView 可拖拽的view,继承自RelativeLayout
Android布局控件之RelativeLayout详解
Android中使用RelativeLayout布局完成的登录界面教学案例任务说明.pdf 学习资料 复习资料 教学资源
LinearLayout和RelativeLayout实现精确布局-简单版 类似与应用评价
Android学习笔记(九):Activity-RelativeLayout