2011-03-11 65 views
12

這是我目前的佈局:如何在單選按鈕之間添加邊距並且可繪製?

<?xml version="1.0" encoding="utf-8"?> 

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scrollview" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="#F5F5DC" 
    > 

     <LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     > 

<RadioGroup 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    > 
    <RadioButton android:id="@+id/radio_red" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:drawableLeft="@drawable/flag_dk" 
     android:textColor="#000000" 
     android:layout_gravity="center_horizontal" 
     android:drawablePadding="10dip" 
     android:text="Danish" /> 
    <RadioButton android:id="@+id/radio_blue" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:drawableLeft="@drawable/flag_en" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginTop="5dip" 

     android:drawablePadding="10dip" 
     android:textColor="#000000" 
     android:text="English" /> 
</RadioGroup> 


</LinearLayout> 
    </ScrollView> 

我得到這個:

enter image description here

我想有一個單選按鈕的標誌(它的繪製)之間的一些空間(保證金)。它甚至有可能嗎?

+2

如果你不介意的標誌,文字的權利,那麼它的位置是'安卓容易調節:drawablePadding'。 – Adinia 2011-03-11 10:03:15

+0

使用drawableRight insted drawableLeft沒有區別。使用這個,在單選按鈕和文本之間沒有空白,而不是在單選按鈕和可繪製之間。 – DixieFlatline 2011-03-11 10:16:07

+0

呃..好像你是對的;我已經在Eclipse中使用Graphical Layout進行了測試,對於Android 1.6到2.2版本,在單選按鈕和文本之間有一個可以理解的邊界,但是從2.3開始看起來這個空間很小,就像在圖片中一樣。 – Adinia 2011-03-11 10:28:13

回答

2

我不認爲有可能使用android apis在圖像和單選按鈕之間添加空格。但是,我認爲你的問題的答案是在圖像本身中添加一些空間。

1

使用相對佈局,而不是線性佈局它給android:layout_margingleft & android:layout_margingRight放棄您的收音機buton &圖像以及。

也給機器人:填充= 「10dip」

嘗試它,它肯定會工作!!!!

3

你在哪裏設置圖像和文本給它之前的空格。例如: :radiobutton.setText(「」+ Text);你會看到所需的輸出。

3

在我的情況下,我有一個自定義可繪製形狀,添加android:paddingDrwable attribure沒有工作,但添加android:paddingLeft="5dp"做。

6

你可以像下面這樣:

<android.support.v7.widget.AppCompatRadioButton 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/view_size" 
     android:button="@null" 
     android:drawablePadding="100dp" 
     android:drawableLeft="?android:attr/listChoiceIndicatorSingle" 
     android:text="label" /> 

enter image description here

相關問題