//绝对布局
AbsoluteLayout abslayout=new AbsoluteLayout (this);
setContentView(abslayout);
Button btn1 = new Button(this);
btn1.setText(”this is a button”);
btn1.setId(1);
AbsoluteLayout.LayoutParams lp1 =
new AbsoluteLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
0,100);
abslayout.addView(btn1, lp1);

//相对布局
RelativeLayout relativeLayout = new RelativeLayout(this);
setContentView(relativeLayout);
AbsoluteLayout abslayout=new AbsoluteLayout (this);
RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
lp1.addRule(RelativeLayout.ALIGN_PARENT_TOP);
lp1.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
relativeLayout.addView(abslayout ,lp1);

//线性布局
LinearLayout ll = new LinearLayout(this);
EditText et = new EditText();
ll.addView(et);

//动态添加布局的方法1.
LinearLayout ll = (LinearLayout)this.getLayoutInflater().inflate(R.layout.main1,null);
setContentView(ll);
LinearLayout ll2 = (LinearLayout)this.getLayoutInflater().inflate(R.layout.main2,ll);
//这样 main2 作为 main1的子布局 加到了 main1的 根节点下

//动态添加布局的方法2 addView.
LinearLayout ll = (LinearLayout)this.getLayoutInflater().inflate(R.layout.main1,null);
setContentView(ll);
LinearLayout ll2 = (LinearLayout)this.getLayoutInflater().inflate(R.layout.main2,null);
ll.addView(ll2);

更多相关文章

  1. 浅谈Java中Collections.sort对List排序的两种方法
  2. Python list sort方法的具体使用
  3. python list.sort()根据多个关键字排序的方法实现
  4. android上一些方法的区别和用法的注意事项
  5. Android(安卓)Activity界面切换添加动画特效
  6. android实现字体闪烁动画的方法
  7. Android中dispatchDraw分析
  8. "Failed to fetch URL https://dl-ssl.google.com/android/repos
  9. Android四大基本组件介绍与生命周期

随机推荐

  1. Android(安卓)WIFI 类分析
  2. Android(安卓)Sensor传感器系统架构初探
  3. Android(安卓)- 文本框的输入法控制和默
  4. 使用SourceInsight查看android中的native
  5. android logo、android开机动画改变详解
  6. android framework 启动流程
  7. Android中Service的使用详解和注意点(Loca
  8. android之view获取getWidth()和getHeight
  9. 〖Android〗Android(安卓)App项目资源字
  10. ANdroid之蓝牙