1

How can we reduce the size of checkbox? Please give me an idea.

MysticMagicϡ
  • 28,593
  • 16
  • 73
  • 124
shripal
  • 1,222
  • 4
  • 19
  • 40

7 Answers7

1

You can define your owm state list drawable, to define different images for different states, as below:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!--When checkbox is checked-->
<item android:state_checked="true" android:drawable="@drawable/img_checkbox_on" />
<!--When checkbox is not checked-->
<item android:state_checked="false" android:drawable="@drawable/img_checkbox_off" />
</selector>

and apply this selector to check box in xml by:

<CheckBox android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:button="@drawable/my_custom_checkbox" />
jeet
  • 29,001
  • 6
  • 52
  • 53
1

UPDATE: this only works from API 17 onwards...


CheckBox derives its height from the TEXT as well as the image.

Set these properties in your XML:

android:text=""
android:textSize="0sp"

Of course this only works if you want no text (worked for me).

Without these changes, the CheckBox was giving me a big margin around my image, as mentioned by Joe Plante.

Richard Le Mesurier
  • 29,432
  • 22
  • 140
  • 255
1

Use android:scaleX="0.5" android:scaleY="0.5"

1 is for 100% size 0.5 is for 50% 0.4 is for 40%...

Gabriel Terry
  • 55
  • 1
  • 6
0

Maybe a different issue. I had a checkbox separate from the text

I did the drawable bit and it didn't work for me. For me, I had a drawable and the checkbox height was stubbornly at a set height, so no matter what, there was space around it. So, I, at first, used m layout_marginTop and layout_marginBottom to negative values, like -15 dip. I admit that it feels like a hack, but it almost worked. The other way was setting the layout_height="20dip" which worked better.

Edit: this requires a layout that has setable margins like Linear and Relative

Dhanuka
  • 2,826
  • 5
  • 27
  • 38
Joe Plante
  • 6,308
  • 2
  • 30
  • 23
0

You can just use scaleX and scaleY properies:

<CheckBox
 android:id="@+id/check_box"            
 android:scaleX="2.5"
 android:scaleY="2.5"/>
  • I realise that this is an old answer. I tried this and while it initially works, as soon as I click on the checkboxes they shrink back to the default 1.0 size. – grolschie Jan 08 '22 at 01:47
0

You can reduce the size of the checkbox by changing its layout_width & layout_height.

bpeterson76
  • 12,918
  • 5
  • 49
  • 82
Parag Chauhan
  • 35,760
  • 13
  • 86
  • 95
  • my frnd i know i cn do with width and height but whats the problem when i reduce the size of width and height it is cutting down the checkbox – shripal Jan 28 '11 at 11:25
  • shirpal defenately u r right if u get any solution pls give me solution – Parag Chauhan Jan 28 '11 at 11:35
  • ok...i think we should make any xml file in that xml file we have to make two images of selected checkbox and unselected checkbox that way we can do... – shripal Feb 01 '11 at 05:28
0

Everything is standard, put in layout xml:

    <CheckBox android:id="@+id/myCheckBoxId"
              android:checked="false"
              android:text="Check It!" 
              android:textSize="12"/> <!--look here --/>
Barmaley
  • 16,638
  • 18
  • 73
  • 146