1

如图所示,我需要设置文本视图 LEFT OF RADIO GROUP,我使用 java 代码完成了它....所以我不知道在 java 代码中为 LAYOUT LEFT OF="" 设置参数.....如何解决它..请以这种方式指导我...

在此处输入图像描述

这是类文件......

protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.rate_me_up);
    textViewShowTime = (TextView) findViewById(R.id.tvTimeCount);
    layout = (RelativeLayout) findViewById(R.id.linear);

    Button btnp = (Button) findViewById(R.id.buttonp);
    btnp.setOnClickListener(this);

}

@Override
public void onClick(View v) {
    RadioGroup radioGroup = new RadioGroup(Rate_me_up.this);
    radioGroup.setOrientation(0);

    RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT,
            RelativeLayout.LayoutParams.WRAP_CONTENT);
    if (mLastRadioGroup != null)
        p.addRule(RelativeLayout.BELOW, mLastRadioGroup.getId());

    radioGroup.setId(mRadioGroupId++);
    mLastRadioGroup = radioGroup;
    layout.addView(radioGroup, p);
    RadioButton radioButtonView = new RadioButton(Rate_me_up.this);
    radioButtonView.setText("radio1");
    radioButtonView.setId(id++);
    radioButtonView.setButtonDrawable(R.drawable.e404);
    radioButtonView.setChecked(false);
    radioGroup.addView(radioButtonView, p);

    RadioButton radioButtonView2 = new RadioButton(Rate_me_up.this);
    radioButtonView2.setText("radio2");
    radioButtonView2.setId(id++);
    radioButtonView2.setChecked(false);
    radioGroup.addView(radioButtonView2, p);
    RadioButton radioButtonView3 = new RadioButton(Rate_me_up.this);
    radioButtonView3.setText("radio3");
    radioButtonView3.setId(id++);
    radioGroup.addView(radioButtonView3, p);
    radioButtonView3.setChecked(false);
    TextView txt = new TextView(Rate_me_up.this);

    txt.setText("FOOD QUALITY!");
    layout.addView(txt, p);

    radioGroup.setOnCheckedChangeListener(this);

}
4

2 回答 2

1

好的,您可以通过以下方式进行操作:

TextView txt = new TextView(Rate_me_up.this);
txt.setText("FOOD QUALITY!");
RelativeLayout.LayoutParams params=
         new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
               LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.LEFT_OF,radiofroup.getId());
txt.setLayoutParams(params);
layout.addView(txt);

希望我回答了你的问题。:)

于 2014-01-30T05:35:16.153 回答
1

addRule做这样的事情..

 RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)button.getLayoutParams();
 params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
 params.addRule(RelativeLayout.LEFT_OF, R.id.id_to_be_left_of);
 button.setLayoutParams(params);
于 2014-01-30T05:19:28.503 回答