how to decrease radio button size in android

前端 未结 4 1985
野性不改
野性不改 2021-01-12 20:42

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

相关标签:
4条回答
  • 2021-01-12 21:03

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

    0 讨论(0)
  • 2021-01-12 21:04

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

    0 讨论(0)
  • 2021-01-12 21:12

    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

    0 讨论(0)
  • 2021-01-12 21:20

    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.

    0 讨论(0)
提交回复
热议问题