2012-06-18 12 views
11

アンドロイド:setTextプロパティでラジオボタンにテキストを設定することができます。しかし、私はそこにテキストが表示されるイメージをしたい..私を助けてください?テキストの代わりにオプションを指定したラジオボタン

+0

あなたが動的に行うにしたい場合、それは、あなたが使用@Anuの答えを使用できることを意味します。そして、あなたのjavaファイルに。そのidを使って 'ImageView'を見つけ、そのためのimagesourceを使います。 – Praveenkumar

+0

ありがとうございます。私は今これを試してみます。 :) –

答えて

13

使用この:drawableRight:アンドロイドを使用して、この約1

<RadioGroup 
    android:id="@+id/radioGroup1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

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

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/ic_launcher" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

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

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/ic_launcher" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

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

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/ic_launcher" /> 
    </LinearLayout> 
</RadioGroup> 
+0

ありがとう..私はこれを試してみます。 –

+0

+1いい回答です。 – Praveenkumar

+32

不都合にも、RadioButtonをLinearLayoutに配置すると、RadioGroupはネストされたボタンのチェック状態の管理を停止します。したがって、RadioGroupは現在役に立たない。 これを使うと、LinearLayoutが不要になり、RadioGroupは入れ子になったRadioButtonを管理することができます。 – petrsyn

19

どのように?

<RadioButton 
     android:id="@+id/map" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:checked="true" 
     android:drawableRight="@drawable/map" /> 

    <RadioButton 
     android:id="@+id/satellite" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:drawableRight="@drawable/sat" /> 
</RadioGroup> 
+3

画像がweb/urlから同期されている場合はどうなりますか? – Killer

+0

正しい答えとして選択されたものよりも良い答え... –

関連する問題