0

I am beginner to android development and I am developing small android application. In my application I m using button. but contains image and text. everything is working fine only thing is that my text displayed at center of button and image at end of button what I want image and text both at center .. My Button code looks like ...

  <Button
                android:id="@+id/signup_button"
                android:layout_width="match_parent"
                 android:layout_height="48dip"
                 android:layout_marginTop="15dip"
                 android:layout_marginLeft="1dip"
                 android:background="@drawable/help_screen_buttons"
                 android:text="Sign up"
                 android:textColor="@color/maroon_font"
                 android:alpha="0.8" 
                 android:textSize="22dip"
                 android:drawableLeft="@drawable/tw_br"/>

He I am only able to set image at left right top bottom position but not at center .. S how to display that image and text at center of button... Need help... thank you...

nilkash
  • 7,408
  • 32
  • 99
  • 176

2 Answers2

0

I hope it's useful to you:

<Button 
    android:id="@+id/startTelemoteButton" 
    android:text="@string/start_telemote"
    android:gravity="center"
    android:width="fill_parent"
    android:height="wrap_content" />
Idrizi.A
  • 9,819
  • 11
  • 47
  • 88
duggu
  • 37,851
  • 12
  • 116
  • 113
  • Hi hcd thank you for reply. I tried this but this will not display my image and text at center ...any other solution .. Thank you – nilkash Feb 11 '13 at 10:29
  • android:src="@drawable/help_screen_buttons" try this – duggu Feb 11 '13 at 10:33
  • Hi HCD thank you reply again.. @drawable/help_screen_button is my drawable xml file in which i defined some background color and some rounded corner. Is it make some change if I make it as src. I will try this as will. – nilkash Feb 11 '13 at 10:52
  • when i use it as src it not applying that to my button.. Any other solution.. Thank you for help – nilkash Feb 11 '13 at 10:59
0

you can simply use image button

 <ImageButton
        android:id="@+id/imageButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:src="@drawable/image" />
Dania Delbani
  • 816
  • 1
  • 11
  • 27