Chinaunix首页 | 论坛 | 博客
  • 博客访问: 200743
  • 博文数量: 102
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1015
  • 用 户 组: 普通用户
  • 注册时间: 2013-06-05 16:45
文章存档

2014年(73)

2013年(29)

我的朋友

分类: Android平台

2013-12-15 17:32:19

01_11_Activity的布局初步(三)
1、相对布局的基本概念
2、相对布局与其他布局的区别
3、相对布局的常用属性介绍

工程Layout03
1、相对布局的基本概念
2、相对布局与其他布局的区别
3、相对布局的常用属性介绍


点击(此处)折叠或打开

  1. //RelativeTest.java
  2. package mars.layout03;

  3. import android.app.Activity;
  4. import android.os.Bundle;

  5. public class RelativeTest extends Activity {
  6.     /** Called when the activity is first created. */
  7.     @Override
  8.     public void onCreate(Bundle savedInstanceState) {
  9.         super.onCreate(savedInstanceState);
  10.         setContentView(R.layout.main);
  11.      // setContentView(R.layout.first);
  12.     }
  13. }

点击(此处)折叠或打开

  1. //main.xml
  2. <?xml version="1.0" encoding="utf-8"?>
  3.     <!--
  4.      两个控件的位置关系
  5.         android:layout_above 将该控件的底部至于给定ID的控件之上
  6.         如:    android:layout_above="@id/xxx"
  7.         android:layout_below 将该控件的顶部至于给定ID的控件之下
  8.         android:layout_toLeftOf 将该控件的右边缘和给定ID的控件的左边缘对齐
  9.         android:layout_toRightOf 将该控件的左边缘和给定ID的控件的右边缘对齐

  10.         两个控件的位置关系(应该是可内嵌、也可不内嵌)
  11.         android:layout_alignBaseline 该控件的baseline和给定ID的控件的baseline对齐
  12.         android:layout_alignBottom 将该控件的底部边缘与给定ID控件的底部边缘
  13.         android:layout_alignLeft 将该控件的左边缘与给定ID控件的左边缘对齐
  14.         android:layout_alignRight 将该控件的右边缘与给定ID控件的右边缘对齐
  15.         android:layout_alignTop 将给定控件的顶部边缘与给定ID控件的顶部对齐

  16.         主要是跟父控件对齐
  17.         android:alignParentBottom 如果该值为true,则将该控件的底部和父控件的底部对齐
  18.         android:layout_alignParentLeft 如果该值为true,则将该控件的左边与父控件的左边对齐
  19.         android:layout_alignParentRight 如果该值为true,则将该控件的右边与父控件的右边对齐
  20.         android:layout_alignParentTop 如果该值为true,则将空间的顶部与父控件的顶部对齐

  21.         居中
  22.         android:layout_centerHorizontal 如果值为真,该控件将被至于水平方向的中央
  23.         android:layout_centerInParent 如果值为真,该控件将被至于父控件水平方向和垂直方向的中央
  24.         android:layout_centerVertical 如果值为真,该控件将被至于垂直方向的中央
  25.     -->
  26. <RelativeLayout xmlns:android=""
  27.                 android:layout_width="fill_parent"
  28.                 android:layout_height="wrap_content"
  29.                 android:padding="10px" >

  30.     <TextView android:id="@+id/label"
  31.               android:layout_width="fill_parent"
  32.               android:layout_height="wrap_content"
  33.               android:text="Type here:" />

  34.     <EditText android:id="@+id/entry"
  35.               android:layout_width="fill_parent"
  36.               android:layout_height="wrap_content"
  37.               android:background="@android:drawable/editbox_background"
  38.               android:layout_below="@id/label" />
  39.   
  40.     <Button android:id="@+id/ok"
  41.             android:layout_width="wrap_content"
  42.             android:layout_height="wrap_content"
  43.             android:layout_below="@id/entry"
  44.             android:layout_alignParentRight="true"
  45.             android:layout_marginLeft="10px"
  46.             android:text="OK" />
  47.             <!-- android:layout_marginLeft="10px" 外边距为10px-->

  48.     <Button android:layout_width="wrap_content"
  49.             android:layout_height="wrap_content"
  50.             android:layout_toLeftOf="@id/ok"
  51.             android:layout_alignTop="@id/ok"
  52.             android:text="Cancel" />
  53. </RelativeLayout>



点击(此处)折叠或打开

  1. //first.xml
  2. <?xml version="1.0" encoding="utf-8"?>

  3. <RelativeLayout xmlns:android=""
  4.                 android:layout_width="fill_parent"
  5.                 android:layout_height="wrap_content"
  6.                 android:padding="10px" >
  7.                 <TextView
  8.                     android:id="@+id/first"
  9.                     android:layout_width="wrap_content"
  10.                     android:layout_height="wrap_content"
  11.                     android:text="first"
  12.                     android:textSize="25pt"
  13.                     android:background="#aa0000">
  14.                 </TextView>
  15.                 <TextView
  16.                     android:id="@+id/second"
  17.                     android:layout_alignTop="@id/first"
  18.                     android:layout_toRightOf="@id/first"
  19.                     android:layout_width="wrap_content"
  20.                     android:layout_height="wrap_content"
  21.                     android:background="#00aa00"
  22.                     android:textSize="25pt"
  23.                     android:text="second"
  24.                     ></TextView>
  25.                 
  26. </RelativeLayout>

相对布局还是多想控件间的关系、多练、多尝试,肯定是OK的

阅读(437) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~