2013-06-20 19 views
1

就像標題一樣 - 是否有可能在RadioGroup附近製作一個標題邊框?或者至少有一個簡單的邊框... 謝謝如何在Android中爲RadioGroup製作標題邊框?

+0

你有一個屏幕截圖什麼你想要還是更好的解釋?你有沒有試過做一個? – codeMagic

+0

我問這個問題,記住了你可以在Java Swing中完成的titledBorder。我試圖尋找這個目的的方法,但找不到一個。順便說一句,我剛開始學習android –

回答

0

標題邊框,我不知道...您可能只想在邊框上添加一個TextView小部件。 但對於一個普通的邊界,這裏是我如何把邊框我的單選按鈕組: 這裏是我的基本單選組(有三個按鈕,水平)

<RadioGroup android:id="@+id/myRadioLayout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="38dp" 
    android:orientation="horizontal" 
    android:elevation="24dp"> 

    <RadioButton android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/radioBtn1" 
     android:text="RadioButton1" android:checked="true" 
     style="@android:style/Widget.CompoundButton.RadioButton" 
     android:textSize="14sp"> 
    </RadioButton> 



    <RadioButton android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/radioBtn2" 
     android:text="RadioButton2" 
     style="@android:style/Widget.CompoundButton.RadioButton" 
     android:textSize="14sp"> 
    </RadioButton> 

    <RadioButton android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/radioBtn3" 
     android:text="RadioButton3" android:checked="true" 
     style="@android:style/Widget.CompoundButton.RadioButton" 
     android:textSize="14sp"> 
    </RadioButton> 
</RadioGroup> 

所以,如果我想圍繞我的單選按鈕邊框組,我將一個xml文件添加到我的可繪製文件夾中。我們稱之爲「border.xml」。 這裏是border.xml代碼:

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <stroke android:width="5px" android:color="#000000" /> 
</shape> 

然後,你將下面的代碼添加到您的無線電集團的xml:

<RadioGroup android:id="@+id/myRadioLayout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="38dp" 
    android:orientation="horizontal" 
    android:background="@drawable/border" 
    android:elevation="24dp"> 

和邊界應該出現在你的單選按鈕組。需要注意的是,你可以改變屬性得到的邊界,漸變,圓角等不同形狀的造型元素可能的屬性,可以在這裏找到:

https://developer.android.com/guide/topics/resources/drawable-resource.html#Shape