//绝对布局
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. TextView添加Onclick点击无效没反应解决办法
  2. Android(安卓)下保持屏幕常亮的实现方法
  3. Android(安卓)okHttp上传单张或多张照片
  4. android 中 LocalSocket的基本使用方法
  5. 修改 android 手机 hosts 文件的方法
  6. Android方法过多MutiDex使用说明
  7. android 取消标题 程序意外停解决方法
  8. 浅谈Java中Collections.sort对List排序的两种方法
  9. Python list sort方法的具体使用

随机推荐

  1. Android 2.2 r1 API 中文文档系列(11) ――
  2. Android下实现电话号码归属地的查询
  3. 【Android】数据库处理
  4. Bmob SDK导入和初始化
  5. Andorid访问WebService的学习笔记
  6. android编程14个很有用的代码片段
  7. Android中滚动的实现
  8. Android gradlew打包命令
  9. Android超人气系列动态壁纸下载(免费)
  10. android 获取视频和图片的缩略图