【android开发】之【android动态布局方法总结】
来源:互联网 发布:java守护线程有什么用 编辑:程序博客网 时间:2024/05/16 07:53
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
http://blog.csdn.net/conanyang/article/details/749548
【Android动态布局】之【ListView动态加载数据】
http://blog.csdn.net/conanyang/article/details/7527486
- 【android开发】之【android动态布局方法总结】
- android动态布局方法总结
- android动态布局方法总结
- android动态布局方法总结
- Android动态布局方法总结
- android动态布局方法总结
- [转载]android动态布局方法总结
- android动态布局方法小结
- android 开发之布局
- android开发之布局
- android 界面布局总结 && Android开发之Linkify【转】
- Android开发之动态创建布局文件及控件
- 【Android动态布局】之【动态插入控件】
- Android开发之UI布局优化全面总结
- Android开发之layout布局
- android 开发布局之LinearLayout
- android 开发布局之FrameLayout
- android 开发布局之RelativeLayout
- android动画实现-Frame animation(一)
- 物理dataguard 正常切换 脚色转换,switchover_status 状态改变
- java ssh mysql实现文件上传下载功能
- Android类参考---Looper
- 证书链验证时出现异常:Signature does not match解决办法
- 【android开发】之【android动态布局方法总结】
- 泛型类:Queue
- 网络编程--IO模型示例
- 微软数据访问接口概述
- Proactor和Reactor模式_继续并发系统设计的扫盲
- C#实现 获取IPv4
- xcode常用快捷键
- Fms3和Flex打造在线多人视频会议和视频聊天(附原代码)<视频聊天,会议开发实例3>
- Smarty中的自定义函数(二)复选框、下拉列表、单选框