相对布局(RelativeLayout)
2016-05-22 10:44
253 查看
相对布局:
特点,所有的控件都是以相对的位置去放置
相对布局需要的关键词汇:
android:layout_centerHorizontal="true" //水平居中
android:layout_centerVertical="true" //竖直居中
android:layout_centerInParent="true" //中心居中
android:layout_alignParentLeft="true" //左
android:layout_alignParentTop="true" //上
android:layout_alignParentRight="true" //右
android:layout_alignParentBottom="true" //下
练习代码如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="中"
android:layout_centerHorizontal="true" //水平居中
android:layout_centerVertical="true" //竖直居中
android:layout_centerInParent="true" //中心居中
android:id="@+id/millde" //添加id
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="上"
android:layout_above="@id/millde"//使用id,在此id表示的button上
android:layout_centerHorizontal="true"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="下"
android:layout_below="@id/millde"//使用id,在此id表示的button下
android:layout_centerInParent="true"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="左"
android:layout_toLeftOf="@id/millde"//使用id,在此id表示的button左
android:layout_centerVertical="true"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="右"
android:layout_toRightOf="@id/millde"//使用id,在此id表示的button右
android:layout_centerVertical="true"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="左上"
android:layout_alignParentLeft="true"//左
android:layout_alignParentTop="true"//上
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="左下"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"//下
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="右下"
android:layout_alignParentRight="true"//右
android:layout_alignParentBottom="true"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="右上"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
/>
</RelativeLayout>
效果:
特点,所有的控件都是以相对的位置去放置
相对布局需要的关键词汇:
android:layout_centerHorizontal="true" //水平居中
android:layout_centerVertical="true" //竖直居中
android:layout_centerInParent="true" //中心居中
android:layout_alignParentLeft="true" //左
android:layout_alignParentTop="true" //上
android:layout_alignParentRight="true" //右
android:layout_alignParentBottom="true" //下
练习代码如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="中"
android:layout_centerHorizontal="true" //水平居中
android:layout_centerVertical="true" //竖直居中
android:layout_centerInParent="true" //中心居中
android:id="@+id/millde" //添加id
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="上"
android:layout_above="@id/millde"//使用id,在此id表示的button上
android:layout_centerHorizontal="true"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="下"
android:layout_below="@id/millde"//使用id,在此id表示的button下
android:layout_centerInParent="true"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="左"
android:layout_toLeftOf="@id/millde"//使用id,在此id表示的button左
android:layout_centerVertical="true"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="右"
android:layout_toRightOf="@id/millde"//使用id,在此id表示的button右
android:layout_centerVertical="true"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="左上"
android:layout_alignParentLeft="true"//左
android:layout_alignParentTop="true"//上
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="左下"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"//下
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="右下"
android:layout_alignParentRight="true"//右
android:layout_alignParentBottom="true"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="右上"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
/>
</RelativeLayout>
效果:
相关文章推荐
- Android布局之RelativeLayout相对布局
- Android RelativeLayout相对布局属性简析
- 浅析Android App的相对布局RelativeLayout
- Android编程动态修改RelativeLayout宽高的方法
- Android编程之绝对布局AbsoluteLayout和相对布局RelativeLayout实例详解
- Android中RelativeLayout相对布局
- relativelayout常用属性
- Android RelativeLayout 属性
- Android日常知识收集与总结之RelativeLayout篇
- RelativeLayout 和LinearLayout比较小tip
- 布局管理器 4----- 相对布局
- Android4.4新的特性,在应用内开启透明状态栏和透明虚拟按钮。
- Android4.4新的特性,在应用内开启透明状态栏和透明虚拟按钮。
- 布局管理
- LinearLayout 和 RelativeLayout
- 关于Android中layout的层次问题-----
- ReletiveLayout布局和分层的认识,欢迎交流。
- 【入门篇】Android学习笔记——常用布局
- Android4.0开发学习之ImageSwitcher
- Android开发中RelativeLayout相对布局