私はAndroidを初めて使用し、xmlなしでAndroidAPIを使用して要素を水平に配置しようとしています。
私がやろうとしているのは、RadioButtonsとEditTextを水平に配置することです。何かのようなもの:
R-----E
R-----E
私はこのようなコードを試しました:
RadioGroup rg = new RadioGroup(this); //create the RadioGroup
rg.setOrientation(RadioGroup.VERTICAL);//or RadioGroup.VERTICAL
for(Map.Entry<String,String> entry : storedCards.entrySet())
{
RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
EditText ed = new EditText(this);
RadioButton rb = new RadioButton(this);
rb.setId(counter++);
lp2.addRule(RelativeLayout.RIGHT_OF,rb.getId());
ed.setLayoutParams(lp2);
rg.addView(rb); //the RadioButtons are added to the radioGroup instead of the layout
rb.setText(entry.getKey());
relativeLayout.addView(ed);
}
これは機能しません。しかし、これは私がやろうとしていることです。まず、counter
変数を使用して各ラジオボタンのIDを設定し、次を使用してそのラジオボタンの右側のサイトにedittextビューを設定しようとしています。
lp2.addRule(RelativeLayout.RIGHT_OF,rb.getId());
しかし、私は適切な結果を得ていません。私はこのようになるだけです:
ER
R
すべてEditText
が重複しています。どこで間違いを犯しているのですか?
前もって感謝します。