user671005
user671005

Reputation: 215

how to decrease radio button size in android

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

Upvotes: 7

Views: 29606

Answers (4)

priyankvex
priyankvex

Reputation: 6040

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.

Upvotes: 3

Avinash Sahu
Avinash Sahu

Reputation: 249

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

Upvotes: 5

Hussain
Hussain

Reputation: 5562

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..

Upvotes: 5

Dinesh Sharma
Dinesh Sharma

Reputation: 11571

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

Upvotes: -1

Related Questions