开发者

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 Chec开发者_高级运维kBox in Android ?

Thanks In Advance,


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


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" />


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜