你好,游客 登录 注册 搜索
背景:
阅读新闻

Android Layout布局

[日期:2013-04-23] 来源:Linux社区  作者:gisshixisheng [字体:大 中 小]

(2) RelativeLayout

相对布局,它是依靠与父容器,同一容器中其它控件的相对位置来排列显示的。主要常用的属性如下:

相对父容器的属性:

Android:layout_alignParentTop: 控件的顶部与父容器的顶部对齐,类似的几个属性从名字可以看出它们的作用:android:layout_alignParentBottom,android:layout_alignParentLeft, android:layout_alignParentRight.

相对同一容器中其它控件的属性:

android:layout_above: 表示此控件在另一控件的上面,类似的还有android:layout_below, android:layout_toLeftOf,android:layout_toRightOf.

android:layout_alignTop: 表示此控件与另一控件顶部对齐,类似的还有android:layout_alignBottom, android:layout_alignLeft,android:layout_alignRight.

既然是相对于另一个控件,就必须在定义这控件时候指定是哪个控件,如控件A的ID为@+id/widget_a, 控件B若要在控件A下面可以这样设置android:layout_below="@id/widget_a"。

来看一下官方的一个Demo:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    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>

linux
相关资讯       Android布局  Android Layout 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款