Android学习笔记 RelativeLayout,TableLayout布局
一.RelativeLayout相对布局方式.
RelativeLayout顾名思义,相对布局,在这个容器内部的子元素们可以使用彼此之间的相对位置或者和容器间的相对位置来进行定位。
注意:不能在RelativeLayout容器本身和他的子元素之间产生循环依赖,比如说,不能将RelativeLayout的高设置成为WRAP_CONTENT的时候将子元素的高设置成为 ALIGN_PARENT_BOTTOM。
RelativeLayout相关的布局属性:
android:layout_above 将该控件置于给定ID的控件之上
android:layout_below 将该控件的置于给定ID控件之下
android:layout_toLeftOf 将该控件置于给定ID的控件之左
android:layout_toRightOf 将该控件置于给定ID的控件之右
RelativeLayout布局中相对于父控件来说位置属性:
android:layout_alignParentLeft 如果为True,该控件位于父控件的左部
android:layout_alignParentRight 如果为True,该控件位于父控件的右部
android:layout_alignParentTop 如果为True,该控件位于父控件的顶部
android:layout_alignParentBottom 如果为True,该控件位于父控件的底部
RelativeLayout布局时对齐相关的属性:
android:layout_alignBaseline 该控件基线对齐给定ID的基线
android:layout_alignBottom 该控件于给定ID的控件底部对齐
android:layout_alignLeft 该控件于给定ID的控件左对齐
android:layout_alignRight 该控件于给定ID的控件右对齐
android:layout_alignTop 该控件于给定ID的控件顶对齐
android:layout_centerHorizontal 如果为True,该控件将被置于水平方向的中央
android:layout_centerInParent 如为Ture,该控件将被置于父控件水平方向和垂直方向
android:layout_centerVertical 如果为True,该控件将被置于垂直方向的中央
Relative布局一:效果图:RelativeLayoutOne布局
布局源码:
<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:padding="10px"
android:background="#00aa00"
tools:context=".RelativeLayoutActivity" >
<TextView
android:id="@+id/tv_heard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textSize="12pt"
android:text="XXX系统登录界面" />
<TextView android:id="@+id/tv_account"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="@id/tv_heard"
android:layout_marginTop="30px"
android:text="用户名:"/>
<EditText android:id="@+id/txt_account"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/tv_heard"
android:layout_toRightOf="@id/tv_account"
android:layout_alignBaseline="@id/tv_account"/>
<TextView android:id="@+id/tv_pwd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tv_account"
android:layout_marginTop="30px"
android:text="密 码:"/>
<EditText android:id="@+id/txt_pwd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txt_account"
android:layout_toRightOf="@id/tv_pwd"
android:layout_alignBaseline="@id/tv_pwd"/>
<Button android:id="@+id/btn_exit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/txt_pwd"
android:layout_alignParentRight="true"
android:layout_marginTop="30px"
android:text="退出"/>
<Button android:id="@+id/btn_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/txt_pwd"
android:layout_toLeftOf="@id/btn_exit"
android:layout_marginTop="30px"
android:layout_marginRight="50px"
android:text="登录"/>
</RelativeLayout>
RelativeLayoutSecond布局效果图:使用 LinearLayout和 RelativeLayout结合布局更加快捷方便。
布局源码:
<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:background="#00aaff"
android:padding="10px"
tools:context=".RelativeLayoutSecondActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textSize="12pt"
android:text="XXX系统登录界面" />
<LinearLayout android:id="@+id/linear_one"
android:layout_below="@id/tv_heard"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="用户名:"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout android:id="@+id/linear_second"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:layout_below="@id/linear_one">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="密 码:"/>
<EditText android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout android:id="@+id/linear_third"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:layout_below="@id/linear_second"
android:gravity="right">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="登录"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30px"
android:text="退出"/>
</LinearLayout>
</RelativeLayout>
>更多相关文章
首页推荐
佛山市东联科技有限公司一直秉承“一切以用户价值为依归
- 01-11全球最受赞誉公司揭晓:苹果连续九年第一
- 12-09罗伯特·莫里斯:让黑客真正变黑
- 12-09谁闯入了中国网络?揭秘美国绝密黑客小组TA
- 12-09警示:iOS6 惊现“闪退”BUG
- 04-29通用智能人“通通”亮相中关村论坛
- 04-29拼多多投入45亿补贴,助力上海“五五购物节
- 04-29通义千问再开源 推出最大尺寸1100亿参数模型
- 04-29【环球视线】比亚迪交付首列出海云轨
- 04-21中国产品数字护照体系加速建设
相关文章
24小时热门资讯
24小时回复排行
热门推荐
最新资讯
操作系统
黑客防御