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);

更多相关文章

  1. Android(安卓)View drawText 文本居中
  2. android对话框弹出方式动画
  3. RadioButton使用的过程中Text文本和图片显示的问题
  4. Android开发学习:ImageView的scaletype属性
  5. android_tips
  6. [Android学习]ImageView的scaletype属性
  7. Android(安卓)ImageView 的scaleType属性
  8. LinearLayout 内部 挂件 居中
  9. [Android] ImageView.ScaleType设置图解

随机推荐

  1. Android(安卓)-- service两种启动方式sta
  2. Android简易计算器——LinearLayout布局
  3. android 使用代码实现 RelativeLayout布
  4. android动效开篇
  5. Android ViewPager 中嵌套webview 的滚动
  6. android 登录Javaeye(使用HttpURLConnect
  7. Android app里打开proguard
  8. Android Frame Animation
  9. 在Android 7.0上PopupWindow.showAsDropD
  10. android用于定时任务工具类