Android学习之线性布局管理器
?
?
?
java形式:
import android.app.Activity;import android.os.Bundle;import android.view.ViewGroup;import android.widget.LinearLayout;import android.widget.TextView;public class MyLinearLayoutDemo extends Activity {@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);LinearLayout layout = new LinearLayout(this);// 创建线性布局LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,// 布局管理器宽度为屏幕宽度ViewGroup.LayoutParams.FILL_PARENT);// 布局管理器高度为屏幕高度layout.setOrientation(LinearLayout.VERTICAL); // 垂直摆放组件LinearLayout.LayoutParams txtParam = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,// 组件宽度为屏幕宽度ViewGroup.LayoutParams.WRAP_CONTENT);// 组件高度为文字高度TextView txt = new TextView(this);// 定义文本显示组件txt.setLayoutParams(txtParam);// 设置文本组件布局参数txt.setText("中华人民共和国");// 设置显示内容txt.setTextSize(20); // 设置文字大小layout.addView(txt, txtParam);// 增加组件super.addContentView(layout, param) ;// 显示布局管理器}}?