Thursday, August 18, 2016

Centering drawable-left image in android Button in XML

Centering drawable-left image in android Button in XML

To center a button drawable left need adjust the padding of button and its drawable left padding.
Giving the Button a fixed width we can do this.

 

  1. <Button
  2. android:layout_below="@+id/imgSave"
  3. android:id="@+id/btninvSearch"
  4. android:layout_width="170dp"
  5. android:layout_height="wrap_content"
  6. android:drawableLeft="@drawable/ic_action_camera"
  7. android:drawablePadding="0dp"
  8. android:paddingLeft="40dp"
  9. android:paddingRight="0dp"
  10. android:paddingTop="12dp"
  11. android:paddingBottom="12dp"
  12. android:gravity="center"

See detail here

No comments:

Post a Comment