Android – set the paintable position within the button

I have a button and a drawable on the left of the text, but I want the drawable to be closer to the text. So I need to move the drawable

I have defined Android: drawableleft, but the content of the button is not centered

This is my code:

<Button
    android:id="@+id/addsubject"
    android:layout_width="250dp"
    android:layout_height="wrap_content"
    android:drawableLeft="@drawable/ic_action_add"
    android:layout_centerHorizontal="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="20dp"
    android:text="@string/addsubject"
    android:textColor="@color/white"
    android:background="@drawable/custombutton1" />

Here's what it looks like now:

Here are my favorite ways:

thank you!

resolvent:

Try this

 <Button
    android:id="@+id/addsubject"
    android:layout_width="160dip"
    android:layout_height="60dip"
    android:layout_gravity="center"
    android:drawableLeft="@drawable/ic_action_add"
    android:drawablePadding="2dip"
    android:gravity="center"
    android:paddingLeft="30dip"
    android:paddingRight="26dip"
    android:singleLine="true"
    android:text="@string/addsubject"
    android:textSize="13dip" />

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>