01 线性布局管理器

一:布局管理器分类:

  1.LinearLayout  : 线性布局管理器,分为水平和垂直两种,只能进行单行布局。
  2.FrameLayout   :所有组件放在左上角,一个覆盖一个。
  3.TableLayout   :任意行和列的表格布局管理器,其中TableRow代表一行,可以向行中增加组件。
  4.RelativeLayout:相对布局管理器,更具最近一个视图组件,或是顶层父组件来确定下一个组件的位置。
  5.废除的布局管理器 :在Android 2.3.3版本之前还存在着一种绝对布局管理器(AbsoluteLayout),
                       此布局管理器使用X、Y轴坐标的形式排列组件。

1.  线性布局管理器

1. 通过main.xml布局配置:
 <LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >  //垂直放置
 ......

 </LinearLayout>

2. 通过Activity动态布局:

package com.LinearLayout;

import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MylLinerLayoutActivity extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		LinearLayout layout = new LinearLayout(this);  //定义线性布局管理器
		LinearLayout.LayoutParams txt = new LinearLayout.LayoutParams(
				LinearLayout.LayoutParams.FILL_PARENT,  //定义布局管理器参数
				LinearLayout.LayoutParams.FILL_PARENT);
		layout.setOrientation(LinearLayout.VERTICAL);  //所有组件采用垂直方式摆放

//下面要定义显示组件的布局管理器,为了简单,本次只定义一个TextView组件		
		LinearLayout.LayoutParams txtView = new LinearLayout.LayoutParams(
				LinearLayout.LayoutParams.FILL_PARENT,  //定义组件的布局管理器参数 
				LinearLayout.LayoutParams.WRAP_CONTENT);
		TextView text1 = new TextView(this); //定义一个文本显示组件
		TextView text2 = new TextView(this); //定义一个文本显示组件
		
		text1.setLayoutParams(txtView); //配置文本显示组件
		
		text1.setText("浙江科技学院");   //配置显示文字
		text2.setText("欢迎光临!");   //配置显示文字
		
		text1.setTextSize(20);
		
		layout.addView(text1, txtView); // 增加组件
		layout.addView(text2, txtView); // 增加组件
		
		setContentView(layout, txt); // 增加新的布局管理器
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值