2011-03-10 71 views
1

現在我有這種佈局(垂直線性佈局內的水平相對佈局),但我需要單選按鈕而不是複選框(用戶必須能夠選擇一個選項)。如何佈置視圖以便可以使用radiogroup?

enter image description here

<LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     > 
<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="10dip" 
    android:layout_marginLeft="5dip" 
    android:layout_marginRight="5dip" 
    android:orientation="horizontal"> 

    <ImageView 
     android:src="@drawable/flag_en" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:adjustViewBounds="true" 
     android:scaleType="fitCenter" 
     android:layout_alignParentLeft="true" /> 

<TextView 
     android:text="English" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:layout_marginLeft="10dip" 
     android:textStyle="bold" 
     android:textSize="20dip"    
     /> 

     <CheckBox android:id="@+id/checkbox4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"  
     android:layout_alignParentRight="true" 
    /> 

    </RelativeLayout>  

    <RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="10dip" 
    android:layout_marginLeft="5dip" 
    android:layout_marginRight="5dip" 
    android:orientation="horizontal"> 

    <ImageView 
     android:src="@drawable/flag_dk" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:adjustViewBounds="true" 
     android:scaleType="fitCenter" 
     android:layout_alignParentLeft="true" /> 

<TextView 
     android:text="Dansk" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:textStyle="bold" 
     android:textSize="20dip"   
     /> 

     <CheckBox android:id="@+id/checkbox5" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"  
     android:layout_alignParentRight="true" 
    /> 

     </RelativeLayout> 
     <Button 
      android:id="@+id/ang_btn" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:text="ang" 
     /> 
     </LinearLayout> 

問題是,RadioGroup中必須放置線性佈局(未相對的)的內部,所以我不能上述佈局中使用。

我怎樣才能達到相同的佈局(多行,3列,第三列單選按鈕),並使用單選按鈕radiogroup?

編輯: 我試過羅比旁氏的解決方案(下),我得到這個: enter image description here

我可以使用,如果我可以把單選按鈕之間有一些空間,這是drawableLeft。我設法在android:drawablePadding =「10dip」(在我上次截圖中沒有看到)之間獲得drawableLeft和文本之間的一些空間。

回答

3

使用無線組和單選按鈕,並使用RadioButton上的android:drawableLeft獲取圖像。

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <RadioGroup ...> 
     <RadioButton ... android:drawableLeft="@drawable/flag_en" android:text="English" /> 
    </RadioGroup> 
</LinearLayout> 
+0

@DixieFlatline Yeah看起來像你可以使用drawablePadding或只是在文本的開頭添加空格。有點煩,你不能指定你想單選按鈕而不是左邊。 – 2011-03-11 14:08:18

+0

非常感謝,先生,您的解決方案爲我工作 – Zia 2014-06-26 07:20:42

相關問題