展会信息港展会大全

RelativeLayout布局常用属性
来源:互联网   发布日期:2015-11-15 09:57:12   浏览:2796次  

导读:先看一下一个布局文件例子: RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/relativeLayout1 android:layout_width=fill_parent android:layout_height=fill_parent TextView android:layout_width=200dp andro...

先看一下一个布局文件例子:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:id="@+id/relativeLayout1"

android:layout_width="fill_parent"

android:layout_height="fill_parent" >

<TextView

android:layout_width="200dp"

android:layout_height="wrap_content"

android:text="RelativeLayout 布局"

android:gravity="center_horizontal"

android:layout_centerHorizontal="true"

android:id="@+id/title"

/>

<TextView

android:layout_width="fill_parent"

android:layout_height="1dp"

android:layout_below="@id/title"

android:id="@+id/line"

android:background="#ffffff"

/>

<Button

android:layout_width="150dp"

android:layout_height="wrap_content"

android:layout_below="@id/line"

android:id="@+id/btn_1"

android:layout_marginLeft="10dp"

android:text="Button One"

/>

<Button

android:layout_width="150dp"

android:layout_height="wrap_content"

android:layout_below="@id/line"

android:id="@+id/btn_2"

android:layout_toRightOf="@id/btn_1"

android:text="Button Two"

/>

</RelativeLayout>

android:gravity="center_horizontal"文字水平居中

android:layout_centerHorizontal="true" 组件水平居中,在相对布局中layout_gravity是不好使的,类似属性还有:android:layout_centerVertical="true"

android:layout_below="@id/title"分割线位于标题(id=title)下边,类似的属性还有:android:layout_above

android:layout_toRightOf="@id/btn_1" 按钮2位于按钮1右边,类似的属性还有:android:layout_toLeftOf

android:layout_marginLeft="10dp" 组件距离父组件左边10dp,类似的属性还有android:layout_marginRight、android:layout_marginTop、android:layout_marginBottom、android:layout_margin、

摘自 wxg630815的专栏

赞助本站

人工智能实验室

相关热词: android开发 教程

AiLab云推荐
推荐内容
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港