2011-03-12 62 views

回答

0

RadioGroup擴展了LinearLayout。那麼兩排是不可能的,我想。
創建包裝RadioGroups組並實現/委派檢查/取消選中和事件偵聽器的包裝器。

0

實際上它有點可能...至少有一部分!

您需要做的是創建一個RelativeLayout,它將包含在您的RadioGroupRadioButton之間。然後,對於每個RadioButton,給RelativeLayout規則來選擇位置,就像這樣:

RadioGroup fromRadioGroup = new RadioGroup(this); 
    RelativeLayout fromChoice = new RelativeLayout(this); 
     RadioButton fromNow = new RadioButton(this); 
     fromNow.setText(R.string.Now); 
     fromNow.setId(1000); 
    fromChoice.addView(fromNow); 
     RadioButton fromTomo = new RadioButton(this); 
     fromTomo.setText(R.string.Tomorrow); 
     RelativeLayout.LayoutParams relParams1 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
     relParams1.addRule(RelativeLayout.RIGHT_OF, 1000); 
     fromTomo.setLayoutParams(relParams1); 
    fromChoice.addView(fromTomo); 
     RadioButton fromNextW = new RadioButton(this); 
     fromNextW.setText(R.string.NextWeek); 
     fromNextW.setId(100100); 
     RelativeLayout.LayoutParams relParams2 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
     relParams2.addRule(RelativeLayout.BELOW, 1000); 
     fromNextW.setLayoutParams(relParams2); 
    fromChoice.addView(fromNextW); 
     RadioButton fromNextM = new RadioButton(this); 
     fromNextM.setText(R.string.NextMonth); 
     fromNextM.setId(100200); 
     RelativeLayout.LayoutParams relParams3 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
     relParams3.addRule(RelativeLayout.BELOW, 1000); 
     relParams3.addRule(RelativeLayout.RIGHT_OF, 100100); 
     fromNextM.setLayoutParams(relParams3); 
    fromChoice.addView(fromNextM); 
fromRadioGroup.addView(fromChoice); 

現在,RadioButton s的兩行顯示,但他們不一樣RadioGroup再參與反應。 ..基本上,我可以從同一組中選擇多個電臺,當看到fromRadioGroup.getCheckedRadioButtonId()返回什麼時,(-1),顯然沒有考慮任何RadioButton作爲孩子......女巫給我們帶來了近乎無用的解決方案。或者也許有辦法強制孩子們回到他們的RadioGroup,但我還沒有找到任何東西。
乾杯。

相關問題