Chinaunix首页 | 论坛 | 博客

OS

  • 博客访问: 2221647
  • 博文数量: 691
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2660
  • 用 户 组: 普通用户
  • 注册时间: 2014-04-05 12:49
个人简介

不浮躁

文章分类

全部博文(691)

文章存档

2019年(1)

2017年(12)

2016年(99)

2015年(207)

2014年(372)

分类: Android平台

2015-11-27 11:10:26

原文地址:相对布局管理器 作者:luozhiyong131

?相对布局管理器指的是参考某一其他控件进行摆放,可以通过控制,将组件摆放在一个指定参考组件的上、下、左、右等位置,这些可以直接通过各个组件提供的属性完成。

点击(此处)折叠或打开

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout                     ?    定义相对布局管理器
  3.     xmlns:android=""
  4.     android:id="@+id/AbsoluteLayout01"             ?    布局管理器ID,程序使用
  5.     android:layout_width="fill_parent"            ?    此布局管理器将占据整个屏幕的宽度
  6.     android:layout_height="fill_parent">        ?    此布局管理器将占据整个屏幕的高度
  7.     <ImageView                    ?    定义图片显示
  8.         android:id="@+id/imga"            ?    此组件ID,程序中使用
  9.         android:src="@drawable/android_mldn_01"    ?    显示图片
  10.         android:layout_width="wrap_content"        ?    组件宽度为图片宽度
  11.         android:layout_height="wrap_content" />    ?    组件高度为图片高度
  12.     <ImageView                    ?    定义图片显示
  13.         android:id="@+id/imgb"            ?    此组件ID,程序中使用
  14.         android:src="@drawable/android_mldn_02"    ?    显示图片
  15.         android:layout_width="wrap_content"        ?    组件宽度为图片宽度
  16.         android:layout_height="wrap_content"     ?    组件高度为图片高度
  17.         android:layout_toRightOf="@id/imga"/>    ?    摆放在imga图片的右边
  18.     <TextView                     ?    定义文本显示组件
  19.         android:text="北京魔乐科技软件学院"         ?    默认显示文字
  20.         android:id="@+id/mytext"        ?    此组件ID,程序中使用
  21.         android:layout_height="wrap_content"     ?    组件高度为文字高度
  22.         android:layout_width="wrap_content"        ?    组件宽度为文字宽度
  23.         android:layout_toRightOf="@id/imga"        ?    组件摆放在imga图片的右边
  24.         android:layout_below="@id/imgb" />        ?    组件摆放在imgb图片的下边
  25.     <Button                     ?    定义普通按钮
  26.         android:text=""     ?    按钮的默认显示文字
  27.         android:id="@+id/mybut"            ?    此组件ID,程序中使用
  28.         android:layout_height="wrap_content"     ?    组件高度为文字高度
  29.         android:layout_width="wrap_content"        ?    组件宽度为文字宽度
  30.         android:layout_below="@id/mytext" />    ?    此组件摆放在mytext组件之下
  31. </RelativeLayout>

点击(此处)折叠或打开

  1. package org.lxh.demo;
  2. import android.app.Activity;
  3. import android.os.Bundle;
  4. import android.view.ViewGroup;
  5. import android.widget.EditText;
  6. import android.widget.RelativeLayout;
  7. public class MyView extends Activity {
  8.     @Override
  9.     public void onCreate(Bundle savedInstanceState) {
  10.         super.onCreate(savedInstanceState);         // 调用父类onCreate()方法
  11.         setContentView(R.layout.main);             // 调用布局文件
  12.         RelativeLayout rl = (RelativeLayout) super.findViewById(R.id.AbsoluteLayout01) ;
  13.         RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(
  14.             ViewGroup.LayoutParams.FILL_PARENT,     // 布局管理器宽度为屏幕宽度
  15.             ViewGroup.LayoutParams.FILL_PARENT         // 布局管理器高度为屏幕高度
  16.         );                     // 设置布局的宽度和高度
  17.         param.addRule(RelativeLayout.BELOW, R.id.mybut);    // 放在mybut组件之下
  18.         param.addRule(RelativeLayout.RIGHT_OF, R.id.imga);    // 放在imga组件右边
  19.         EditText text = new EditText(this) ;        // 定义文本输入框
  20.         rl.addView(text,param) ;            // 加入组件
  21.     }
  22. }

020504_相对布局管理器:RelativeLayout.ppt
阅读(1277) | 评论(0) | 转发(0) |
0

上一篇:单击事件

下一篇:TableLayout

给主人留下些什么吧!~~