2011-04-14 96 views
3

嘿,我想打一個單選按鈕的文字出現在單選按鈕的左邊..所以我試着用2層相對的觀點(我有2個單選按鈕)和它的工作,但問題是在RadioGroup中工作不正常..繼承人的代碼:使用RadioGroup中和單選按鈕

<RelativeLayout android:id="@+id/SearchRelative" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 

    <RadioButton android:checked="true" 
     android:id="@+id/SearchRadioButtonAloneWord" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true"> 
    </RadioButton> 

    <TextView android:text="1" 
     android:layout_toLeftOf="@+id/SearchRadioButtonAloneWord" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 
    </TextView> 
</RelativeLayout> 

<RelativeLayout android:id="@+id/SearchRelative" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 

    <RadioButton android:id="@+id/SearchRadioButtonInBetweenWord" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true"> 
    </RadioButton> 

    <TextView android:text="2" 
     android:layout_toLeftOf="@+id/SearchRadioButtonInBetweenWord" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 
    </TextView> 
</RelativeLayout> 

他們得到與文本正確顯示其RadioButton左側..但RadioGroup不工作!
我該如何解決這個問題?
感謝

EDIT1:是否有可能動態地添加RadioButton s到一組?這是解決我的問題的一種方法!

回答

4

使用RadioGroup內部佈局管理器關於:對不起,這是行不通的方式。據我知道,如果事情被添加到RadioGroup這是不是RadioButton一個實例,它不受此RadioGroup管理。但是這給問題提供了一個交替的解決方案:擴展RadioButton以按照你想要的方式繪製。

至於動態操縱:是的,這與RadioGroup一樣可能,就像任何其他ViewGroup一樣。所有你需要做的就是通過RadioGroup.addView()添加RadioButton秒。

+0

「延長單選畫它,你想要的方式。」能否請您解釋越多,你的意思 – Omar 2011-04-14 17:43:36

+0

您可以創建自己的UI組件,並將其包含在你的佈局。開發人員指南有關於如何執行此操作的文章:http://developer.android.com/guide/topics/ui/custom-components.html。您需要閱讀最後一節「修改現有視圖類型」。 – Malcolm 2011-04-14 17:57:55

相關問題