python 控件 相对布局_Android UI控件系列:RelativeLayout(相对布局)

RelativeLayout是一个在相对位置上显示子View元素的VeiwGroup,一个视图的位置,可以指定为相对于兄妹的元素(比如一个给定的与孙的左边或者下边)或者心爱那个对于RelativeLayout区域的位置(比如与底部对齐,剩下的中心)

一个RelativeLayout是一个非常强大使用的为设置用户界面的布局,因为它可以消除嵌套的视图组ViewGroup,如过你发现你用了几个嵌套的LinearLayout组,你可以替换为一个单独的RelativeLayout

1、开始一个新的工程,名字叫做HelloRelativeLayout

2、打开res/layout/main.xml文件并且插入如下信息<?xml version="1.0" encoding="utf-8"?>

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

android:id="@+id/label"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="Type here:"

/>

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"

/>

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"

/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_toLeftOf="@id/ok"

android:layout_alignTop="@id/ok"

android:text="Cancel"

/>

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、你可以看到如下的布局

d8f5324f74ee6623a10079272435f462.gif

以上就是Android UI控件系列:RelativeLayout(相对布局)的内容,更多相关内容请关注PHP中文网(www.php.cn)!

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值