我正在尝试以编程方式对齐左侧单选按钮的文本和右侧的按钮,而不是下一个屏幕截图中显示的内容
我试图创建一个相对布局并放置 textview 和 radiobtn(没有文本),但每次尝试都不成功:(
我在这里发布了我尝试运行但无法对齐的代码。
RelativeLayout relLay = new RelativeLayout(this);
relLay.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
TextView textView=new TextView(this);
textView.setText(device.getName());
textView.setGravity(Gravity.LEFT);
RadioButton radioBtn= new RadioButton(this);
radioBtn.setText(" ");
radioBtn.setTag(device);
radioBtn.setChecked(false);
radioBtn.setGravity(Gravity.RIGHT);
RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
lp1.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
lp2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT,RelativeLayout.TRUE);
relLay.addView(textView,lp1);
relLay.addView(radioBtn,lp2);
radioGr.addView(relLay);
我还必须指出,我正在将相对布局添加到由 ScrollView 包含的无线电组中。
预先感谢您的帮助和耐心