我的佈局XML是什麼樣子的Android RadioGroup中水平對齊的內容不可見
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollview1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/linearlayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
我創造RadioGroup中和
LinearLayout ll = (LinearLayout)findViewById(R.id.linearlayout1);
RadioGroup rg = new RadioGroup(this);
rg.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
rg.setOrientation(0);
while(itr.hasNext()){
final String drinkname = itr.next();
System.out.println("drinkname: "+drinkname);
RadioButton rb = new RadioButton(this);
rb.setText(drinkname);
rg.addView(rb);
}
rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
//group.clearCheck();
int id = group.getCheckedRadioButtonId();
RadioButton selectrb = (RadioButton) findViewById(id);
System.out.println(selectrb.getText().toString());
WebMenu.drinkname = selectrb.getText().toString();
}
});
ll.addView(rg);
它應該表現出6個值通過代碼添加單選按鈕;但它只顯示3個,剩餘看起來像隱藏。有人可以幫我嗎?
在此先感謝!
請問您可以添加圖片嗎? – joao2fast4u 2014-11-23 20:55:15
你的代碼工作正常。你確定你的迭代器有6個元素嗎? – joao2fast4u 2014-11-23 21:11:21
@ joao2fast4u - SO不允許添加圖片。我已經加入了保管箱。請找到鏈接。 https://www.dropbox.com/s/kju5uawmsfxhome/SO1.png?dl=0 – Prabhu 2014-11-23 22:04:01