android动态布局方法总结

//绝对布局
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 = newRelativeLayout.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 linearlayout= (LinearLayout)this.getLayoutInflater().inflate(R.layout.main1,null);

setContentView(linearlayout);

LinearLayout linearlayout2 = (LinearLayout)this.getLayoutInflater().inflate(R.layout.main2,linearlayout);

//这样main2作为main1的子布局 加到了main1的 根节点下

//动态添加布局的方法2 addView.

LinearLayout linearlayout = (LinearLayout)this.getLayoutInflater().inflate(R.layout.main1,null);

setContentView(linearlayout);

LinearLayout linearlayout2 = (LinearLayout)this.getLayoutInflater().inflate(R.layout.main2,null);

linearlayout.addView(linearlayout2);


转自:http://wenzhutech.diandian.com/post/2011-12-17/12930666



相关文章:

【Android动态布局】之【LayoutInflater的使用】

http://blog.csdn.net/conanyang/article/details/7496335

【android动态布局】之【LayoutInflater(inflate )的使用】

http://blog.csdn.net/conanyang/article/details/7542930

【Android动态布局】之【动态插入控件】

http://blog.csdn.net/conanyang/article/details/749548

【Android动态布局】之【ListView动态加载数据】

http://blog.csdn.net/conanyang/article/details/7527486


更多相关文章

  1. TextView添加Onclick点击无效没反应解决办法
  2. Android程序——退出程序的时候杀死所有进程的一个方法
  3. android利用OpenGLES开发动态壁纸用到的GLWallpaperService类
  4. H5调android 的方法修改UI无效
  5. android的ndk修改app_platform的方法,亲测绝对可行
  6. Android(安卓)通过接口的方式去调用服务里面的方法
  7. Android(安卓)MedaiPlayer类的简单介绍
  8. 浅谈Java中Collections.sort对List排序的两种方法
  9. Python list sort方法的具体使用

随机推荐

  1. 如何在Android系统源码中添加一个C项目?
  2. android 图片的缩放,bitmap的用法
  3. Android,ijkplayer增加https协议支持,编译
  4. Android电源管理简介(上)
  5. Dagger2的理解和使用
  6. Android基于XMPP Smack openfire 开发的
  7. android:configChanges=”locale”
  8. 80、Android搭建RN开发环境
  9. android绘画- View onDraw 一点疑惑
  10. Android里监视数据库的变化 registerCont