David Cesarino David Cesarino - 1 year ago 253
Android Question

Center CheckBox drawable within itself

I have a

that I want centered within its own boundaries, not pushed to the side. Probably easier demonstrated than explained:

enter image description here

Note that it isn't centered. Currently defined as:


android:minWidth="48dp" />

Nevermind the custom button drawable. It behaves the same with a vanilla
as well (the small check box behaves the same).

Sam Sam
Answer Source

I believe the problem is that the Checkbox widget uses a regular TextView with the drawableLeft attribute, because it expects text to be shown as well. (This is why you see it centered vertically, but offset slightly to the left.)

If you simply want an image button with multiple states, I suggest using a ToggleButton with your custom images in a state list selector. Or you could create a custom class that extends ImageView and implements Checkable.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download