android layout动态布局
2014-07-24 16:39
246 查看
RelativeLayout rl = new RelativeLayout(this); Button btn1 = new Button(this); btn1.setText("----------------------"); btn1.setId(1); 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); // btn1 位于父 View 的顶部,在父 View 中水平居中 rl.addView(btn1, lp1 ); Button btn2 = new Button(this); btn2.setText("|\n|\n|\n|\n|\n|"); btn2.setId(2); RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); lp2.addRule(RelativeLayout.BELOW, 1); lp2.addRule(RelativeLayout.ALIGN_LEFT, 1); // btn2 位于 btn1 的下方、其左边和 btn1 的左边对齐 rl.addView(btn2, lp2); Button btn3 = new Button(this); btn3.setText("|\n|\n|\n|\n|\n|"); btn3.setId(3); RelativeLayout.LayoutParams lp3 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); lp3.addRule(RelativeLayout.BELOW, 1); lp3.addRule(RelativeLayout.RIGHT_OF, 2); lp3.addRule(RelativeLayout.ALIGN_RIGHT, 1); // btn3 位于 btn1 的下方、btn2 的右方且其右边和 btn1 的右边对齐(要扩充) rl.addView(btn3,lp3); Button btn4 = new Button(this); btn4.setText("--------------------------------------------"); btn4.setId(4); RelativeLayout.LayoutParams lp4 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); lp4.addRule(RelativeLayout.BELOW, 2); lp4.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE); // btn4 位于 btn2 的下方,在父 Veiw 中水平居中 rl.addView(btn4,lp4); setContentView(rl);
相关文章推荐
- Android使用TableLayout动态布局实例(转)
- Android笔记之动态改变layout中的布局
- Android 利用layoutParams代码动态布局空间位置
- android客户端学习-RelativeLayout布局动态在四个角的位置增加标签
- android控件学习二:使用LayoutInflater动态加载布局和操作控件
- android在java代码中动态添加组件及相关布局方法(LayoutParams)
- Android - 布局管理器LayoutInflater及LayoutParams动态设置宽高属性
- Android 动态添加布局(layout)和控件(Widget)
- android动态设置布局LayoutInflater的使用详解
- android 动态调整RelativeLayout布局控件的相对位置 layout_toLeftOf 之类的
- Android-LayoutInflater的使用(android 动态布局文件)
- android布局中子View添加动态隐藏和显示的动画效果。(LayoutTransition)
- 【Android动态布局】之【LayoutInflater的使用】
- Android动态设置布局的LayoutParams属性总遇到造型异常
- Android 动态改变布局属性RelativeLayout.LayoutParams.addRule()
- android,利用layoutParams代码动态布局空间位置
- Android约束布局ConstraintLayout动态设置Id失效问题解决办法
- Android 在Class文件里动态调用一个layout布局文件
- Android表格布局TableLayout简单实现(Java动态添加,设置边框,删除数据(单行,多行))
- 学习android笔记(5) 动态建立TableLayout 表格布局