Button with the center of the image and text

I need a button with text in the middle and an icon to the left of the text.

my button:

<Button
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:onClick=""
            android:text="@string/search_button"
            android:textColor="@drawable/button_text"
            android:layout_weight="1"
            android:background="@drawable/button"
            android:drawableLeft="@drawable/new_star_nonactive" />

I need a button with fill_parent width (full screen width)

but I have this: enter image description here

How to set the center of image positioning next to the text?

+5
source share
3 answers

Then the only way to do this is to use a residence permit. In your case, you want the image to move to the right, so use android:paddingLeft="50dp"either the number of dips you want to move.

EDIT: also add android:gravity="left | center"to get text with image.

+14
source

Try this, you will definitely get the result:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
     >

    <Button 
        android:id="@+id/btn"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="hi"
        android:textSize="24sp"
        android:background="@drawable/wood"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/btn"
        android:layout_alignBottom="@+id/btn"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="90dp"
        android:background="@drawable/ic_launcher"
        android:gravity="center" />

</RelativeLayout>
0
source

,

<Button 
    android:background="@null"
    android:layout_marginLeft="0dp" 
    android:text="HOME"
    android:layout_width="62dp"
    android:marqueeRepeatLimit="marquee_forever"
    android:textColor="#ffffff" 
    android:layout_height="50dp" 
    android:ellipsize="marquee" 
    android:drawableLeft="@drawable/icon_home" 
    android:id="@+id/homebtn" 
    android:singleLine="true"
    android:textSize="10dp"
   android:paddingTop="6dp"
    android:layout_alignParentLeft="true">
  </Button>
0

All Articles