How to decrease the Width and Height of CheckBox i

2019-07-18 14:13发布

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,

3条回答
Rolldiameter
2楼-- · 2019-07-18 14:39

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

查看更多
我想做一个坏孩纸
3楼-- · 2019-07-18 14:52

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" />
查看更多
Juvenile、少年°
4楼-- · 2019-07-18 14:52

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

查看更多
登录 后发表回答