Android_programmer_camera
Android_programmer_camera

Reputation: 13349

How to decrease the Width and Height of CheckBox in Android

Can anyone tell me how to reduce the width and height of CheckBox in order to display very small CheckBox in Android ?

Thanks In Advance,

Upvotes: 2

Views: 5521

Answers (3)

Richard Le Mesurier
Richard Le Mesurier

Reputation: 29713

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


As per my answer on this question: - how can we reduce the size of checkbox please give me an idea


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

Upvotes: 0

BeRecursive
BeRecursive

Reputation: 6366

setWidth(int) and setHeight(int) since CheckBox extends CompoundButton which extends Button

Try referring to this tutorial

Alernatively try changing it via the XML:

<CheckBox 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:text="new checkbox" 
    android:background="@drawable/my_checkbox_background"
    android:button="@drawable/my_checkbox" />

Upvotes: 1

kiki
kiki

Reputation: 13987

Simply use setWidth(w) and setHeight(h) functions as you would for a normal Button.

Upvotes: 1

Related Questions