2012-06-18 11 views
11

मैं छवि के रूप में विकल्प के साथ एंड्रॉइड ऐप में रेडियो बटन कैसे जोड़ सकता हूं, पाठ नहीं .. हम टेक्स्ट को एंड्रॉइड द्वारा सेट बटन पर सेट कर सकते हैं: setText property। लेकिन मैं एक छवि को वहां प्रदर्शित करना चाहता हूं, पाठ नहीं .. कृपया मेरी मदद करें?पाठ के बजाय छवि के साथ रेडियो बटन

+0

आप गतिशील रूप से इसका मतलब है कि ऐसा करने के लिए चाहते हैं, आप का उपयोग उपयोग @Anu जवाब कर सकते हैं। और, आपकी जावा फाइल में। बस अपनी आईडी के साथ 'छवि दृश्य' ढूंढें और इसके लिए छवि स्रोत का उपयोग करें। – Praveenkumar

+0

बहुत बहुत धन्यवाद .. मैं अब कोशिश करूँगा। :) –

उत्तर

13

उपयोग करें:

<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

दुर्भाग्य से रेडियोबटन को लाइनरलाउट में डालने का कारण बनता है कि रेडियो समूह नेस्टेड बटनों के चेक किए गए राज्यों को प्रबंधित करना बंद कर देगा। इसलिए रेडियो ग्रुप अब बेकार है। <रेडियोबटन एंड्रॉइड: drawableRight = "@ drawable/ic_launcher" का उपयोग करने पर विचार करें> यह avoids को लाइनरलाइट के लिए जरूरी है और रेडियो समूह नेस्टेड रेडियोबटन के प्रबंधन में अपना काम कर सकता है। – petrsyn

19

कैसे आप इसका उपयोग एंड्रॉयड के बारे में: drawableRight?

<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

क्या होगा यदि छवियां वेब/यूआरएल से सिंक हो? – Killer

+0

सही उत्तर के रूप में चुने गए से बेहतर उत्तर ... –

संबंधित मुद्दे