2012-01-25 15 views
11

ラジオボタンのリストを4つ作成しようとしています。各項目には、テキストが右側にある必要がありますが、テキストの右側にも画像があります。イメージはラジオボタン自体ではなく、オプションを説明するイメージです。 私は運がまだまだありません。デザイナーは物事を置くのに役に立たないようです。これをXMLでコーディングする方法を知っておく必要があります。私は成功しません、最初のラジオボタンの右に一つの画像を配置するtryiongています。ここラジオボタンの右側に画像を置く方法

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" android:weightSum="1" android:baselineAligned="true" android:orientation="horizontal"> 
    <RadioGroup android:layout_weight="0.50" android:layout_height="wrap_content" android:id="@+id/radioGroup1" android:layout_width="0dp"> 
     <RadioButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:checked="true" android:text="A" android:id="@+id/radio0"></RadioButton> 
     <ImageView android:layout_toRightOf="@id/radio0" android:layout_height="wrap_content" android:src="@drawable/A2" android:layout_width="wrap_content" android:id="@+id/imageView1"></ImageView> 
     <RadioButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="B" android:id="@+id/radio1"></RadioButton> 
     <RadioButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="C" android:id="@+id/radio2"></RadioButton> 
     <RadioButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="D" android:id="@+id/radio3"></RadioButton> 
    </RadioGroup> 

</LinearLayout> 

: 私のXMLは次のようになります。 ラジオボタンの右側に画像を配置するにはどうすればよいですか?

答えて

17

ボタンの場合は、上/右/左/下にドロアブルを配置できます。だから私はそれがラジオボタンのために同じように動作するかもしれないと思った。あなたはこれを試していました

は、Androidデベロッパーサイト

this linkを見たことがありますか?画像を追加するには、あなたのビューで

更新

だからあなたの場合には、ImageViewのを削除し、android:drawableRight(または左/トップ/ボトム)を追加するには、ラジオボタンで

<RadioButton 
    android:drawableRight="@drawable/A2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:checked="true" 
    android:text="A" 
    android:id="@+id/radio0"/> 
0

使用android:drawableXXXXX /描画可能いくつかのパディングを追加したい場合はdrawableパディングを使用してください。

1
<RadioButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:drawableLeft="@drawable/ic_launcher"/> 

RadioButton自体にはデフォルトでTextViewが含まれています。したがって、TextViewのすべての操作を行うことができます。

BONUS:チェックステータスを示す円の点を変更するには、アンドロイド:ボタンタグを更新して、独自のドロアブルを参照するだけです。

関連する問題