7

can we decrease the size of radio button in android ??

user671005
  • 215
  • 2
  • 4
  • 9
  • http://stackoverflow.com/questions/4259295/how-can-i-set-the-width-of-radio-buttons-to-change-with-regards-to-screen-size is your solution. And here is another article for [change look of CheckBox](http://www.anddev.org/tutorial_change_look_of_checkbox-t4553.html) – Pankaj Kumar Apr 05 '11 at 05:10

4 Answers4

5

If you are using radio button then normally it takes image resource from android-sdk e.g . /android-sdk-macosx/platforms/android-10/data/res/drawable-hdpi

If you want to customize it then take the resource from this folder and resize it (I got it of size 34 x 48 which resized to 19 x 24) Then you can use it Like this:

Here is my radio_button.xml

 <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/btn_radio_on" android:state_checked="true" android:state_pressed="false"/>
    <item android:drawable="@drawable/btn_radio_off" android:state_checked="false" android:state_pressed="false"/>
    <item android:drawable="@drawable/btn_radio_on_pressed" android:state_checked="true" android:state_pressed="true"/>
    <item android:drawable="@drawable/btn_radio_off_pressed" android:state_checked="false" android:state_pressed="true"/>

</selector>

Here is my main.xml

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <RadioGroup
        android:layout_width="fill_parent"
        android:layout_height="30dp"
        android:checkedButton="@+id/first"
        android:orientation="horizontal" >

        <RadioButton
            android:id="@+id/first"
            android:button="@drawable/radio_button"
            android:height="20dp"
            android:width="20dp" />

        <RadioButton
            android:id="@+id/second"
            android:button="@drawable/radio_button"
            android:height="20dp"
            android:width="20dp" />

        <RadioButton
            android:id="@+id/third"
            android:button="@drawable/radio_button"
            android:height="20dp"
            android:width="20dp" />

        <RadioButton
            android:id="@+id/fourth"
            android:button="@drawable/radio_button"
            android:height="20dp"
            android:width="20dp" />
    </RadioGroup>

</LinearLayout>

Due to less reputation I am not able to upload images here so I am giving link for resources and output image.

https://www.dropbox.com/sh/7518zf3onh4su0z/fO7CP7o1EY

Avinash Sahu
  • 249
  • 3
  • 19
5

As far as i know the radio button can be done but not like the other EditText or TextView..

Try this code..

<RadioGroup android:layout_width="fill_parent"               
            android:layout_height="50dp"           
            android:orientation="horizontal"         
            android:checkedButton="@+id/first">  

 <RadioButton android:id="@+id/first"        
      android:width="50dp"        
      android:height="50dp"        
      android:button="@drawable/button_radio"/> 

   <RadioButton android:id="@+id/second"        
      android:width="50dp"     
      android:height="50dp"     
      android:button="@drawable/button_radio"/>

   <RadioButton android:id="@+id/third"
      android:width="50dp"
      android:height="50dp"
      android:button="@drawable/button_radio"/>

   <RadioButton android:id="@+id/fourth"                                          
      android:width="50dp"              
      android:height="50dp"           
      android:button="@drawable/button_radio"/>           
</RadioGroup>

And also take a look at this Sample.. This will help you alot..

GAMA
  • 5,958
  • 14
  • 79
  • 126
Hussain
  • 5,552
  • 4
  • 40
  • 50
  • And one more thing how to make it checkable when i click on any of these button – user671005 Apr 05 '11 at 06:18
  • Im not sure about this but i think u have to use the StateListDrawable.. Just have a look at these two samples. U can get to know something.. http://heliodorj.blogspot.com/2009/04/androids-statelistdrawable-example.html and http://developer.android.com/reference/android/graphics/drawable/StateListDrawable.html – Hussain Apr 05 '11 at 06:30
3

An easy way to decrease the size of radio buttons can be :

<RadioButton android:scaleX="0.75" android:scaleY="0.75" />

It can cause some scaling issues when you are increasing the size but for decreasing the size it should work fine.

priyankvex
  • 5,760
  • 5
  • 28
  • 44
-1

I think it cant be done as the Radio Buttons are built in component and its size is fixed.

Dinesh Sharma
  • 11,533
  • 7
  • 42
  • 60