0

I want to create button where I have icon and text. This is what I created:

enter image description here

This is xml:

        <Button
            android:id="@+id/call_button"
            android:layout_width="match_parent"
            android:layout_height="0dp"
          android:layout_marginTop="30dp"
            android:background="@drawable/button"
            android:layout_weight="40" 
            android:drawableLeft="@drawable/phone"
            android:text="Call"
            android:textColor="@color/white"
            />

How I can move this phone icon closer text?

edi233
  • 3,511
  • 13
  • 56
  • 97

4 Answers4

1

Did you try providing paddingLeft attribute.

<Button android:drawableLeft="@drawable/ic_launcher"
        android:layout_width="100dip"
        android:paddingLeft="10dip"
        android:layout_height="50dip"
        android:text="hello" />

It helped me to move the Drawable towards the Text.

Andro Selva
  • 53,910
  • 52
  • 193
  • 240
1

This may guide you for arrangements,

http://developer.android.com/resources/articles/layout-tricks-efficiency.html

Code:

<Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/home_btn_test"
        android:drawableTop="@drawable/home_icon_test"
        android:textColor="#FFFFFF"
        android:id="@+id/ButtonTest"
        android:paddingTop="32sp"
        android:drawablePadding="-15sp"
        android:text="this is text"></Button>

ref from: Android: combining text & image on a Button or ImageButton

Refer here also: http://www.mokasocial.com/2010/04/create-a-button-with-an-image-and-text-android/

Community
  • 1
  • 1
Ponmalar
  • 6,871
  • 10
  • 50
  • 80
0

I'm afraid that you cannot set the compound drawable's position, but you may add some transparent pixels arround your image and that should do it :)

Iulia Barbu
  • 1,522
  • 12
  • 25
0

You can do one thing. Create an image as you like and put it in to the drawable folder. Create an image view and set that image, then you can set the onclick event to that image.

ImageView img = (ImageView) findViewById(R.id.myImageId);
img.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
   // your code here
}
}); 
sachi
  • 2,122
  • 7
  • 30
  • 46