Android - Spacing between CheckBox and text

前端 未结 29 2913
广开言路
广开言路 2020-11-27 09:24

Is there an easy way to add padding between the checkbox in a CheckBox control, and the associated text?

I cannot just add leading spaces, because my label is multi-

29条回答
  •  一个人的身影
    2020-11-27 09:46

    As you probably use a drawable selector for your android:button property you need to add android:constantSize="true" and/or specify a default drawable like this:

    
    
      
      
    
    

    After that you need to specify android:paddingLeft attribute in your checkbox xml.

    Cons:

    In the layout editor you will the text going under the checkbox with api 16 and below, in that case you can fix it by creating you custom checkbox class like suggested but for api level 16.

    Rationale:

    it is a bug as StateListDrawable#getIntrinsicWidth() call is used internally in CompoundButton but it may return < 0 value if there is no current state and no constant size is used.

提交回复
热议问题