how to add space in start when add image in button - android

how do I add some space when adding image in button? this is my code below and the image is URL which show image button and text on the button but the image shows left most side of the button.
I want to add some space in the start of the image like this image which URL is.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="45dp"
android:orientation="horizontal" >
<Button android:id="#+id/MyAccountbutton"
style="?android:attr/buttonStyleSmall"
android:layout_height="25dip"
android:layout_width="fill_parent"
android:layout_marginRight="35dip"
android:layout_marginLeft="35dip"
android:drawableLeft="#drawable/Handshake"
android:background="#drawable/curvedplanebutton"
android:textColor="#drawable/button_text_color"
android:layout_marginTop="15dip"
android:text="Payments"/>
</LinearLayout>

Add some android:drawablePadding so that image will have some space. Change your button code with below code:
<Button android:id="#+id/MyAccountbutton"
style="?android:attr/buttonStyleSmall"
android:layout_height="25dip"
android:layout_width="fill_parent"
android:layout_marginRight="35dip"
android:layout_marginLeft="35dip"
android:drawableLeft="#drawable/Handshake"
android:drawablePadding="5dp"
android:background="#drawable/curvedplanebutton"
android:textColor="#drawable/button_text_color"
android:layout_marginTop="15dip"
android:text="Payments"/>

Add android:drawablePadding="16dip" and android:paddingLeft="16dip" to the Button.

Related

center image inside button

i have this code for displaying an image on a button.
How to position the image so that it doesn't touch the frame/border?
this the code:
<Button
android:layout_width="0dp"
android:layout_weight="0.45"
android:onClick="EXIT"
android:layout_height="95dp"
android:text="Exit"
android:textSize="22sp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:background="#drawable/buttonnew"
android:textStyle="bold"
android:drawableTop="#drawable/zexit"
android:textColor="#000000"
android:layout_gravity="bottom"
/>
Since you are referring to the Button rather than the drawable, it would be best to use padding instead of margin, e.g. android:paddingTop

how do I make an image fit in my button

each time I add and image to my button (want to add it below the text) it only shows the top left of the image and adds itself at the top of the button even when I use android:drawableBottom .
here is my XML code :
<Button
android:layout_width="162dp"
android:layout_height="200dp"
android:text="#string/weather_station"
android:textStyle="bold"
android:textSize="18dp"
android:background="#drawable/weather"
android:paddingBottom="120dp"
android:paddingLeft="5dp"
android:typeface="monospace"
android:id="#+id/weather_station" />
android:drawableBottom="#drawable/weatherman"
/>
use ImageButton instead of using Button and try to scale the image`
<ImageButton
android:id="#+id/my_image_button"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:src="#drawable/my_img" />
<Button
android:layout_width="162dp"
android:layout_height="200dp"
android:text="bUTTON"
android:textStyle="bold"
android:textSize="18dp"
android:background="#drawable/shape1"
android:paddingBottom="120dp"
android:paddingLeft="5dp"
android:drawableBottom="#drawable/cast_ic_notification_2"
android:typeface="monospace"
android:id="#+id/weather_station" />
how cant it possible even your drawable line out of scop ? try above WORKING CODE
Try setting up the below scale type in the xml for fill image in button.
android:scaleType="scaleXY"
So put this attribute in your xml code.
<Button
android:layout_width="162dp"
android:layout_height="200dp"
android:text="#string/weather_station"
android:textStyle="bold"
android:textSize="18dp"
android:background="#drawable/weather"
android:paddingBottom="120dp"
android:scaleType="scaleXY"
android:paddingLeft="5dp"
android:typeface="monospace"
android:id="#+id/weather_station"
android:drawableBottom="#drawable/weatherman"/>

how to place text on button at edges in android

I want to place text in a button on the extreme edges that is
Click on the left part of the button and Here on the right part of the button. How this can be achieved.
i have used the TAGandroid:text="Click Here", as the button is on the full screen i want these words to be at extreme edges
Use the below RelativeLayout. You can customize the values. Here you can make all of the RelativeLayout and TextViews act like a button by setting them OnClickListeners.
<RelativeLayout
android:id="#+id/mybutton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:background="#3983B1" >
<TextView
android:id="#+id/leftButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Click"
android:textColor="#ffffff" />
<TextView
android:id="#+id/rightButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Here"
android:textColor="#ffffff" />
</RelativeLayout>
The layout looks like:

how do I align text and image in same button

How do I align text and image with same button? I want to do like this image:
but my button looks like this, with text overlapping the image:
This is my code below. How do I make space in between text and image in the same button?
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_weight="0"
android:weightSum="1"
android:orientation="horizontal" >
<Button android:id="#+id/btnUtilitybillpayments"
style="?android:attr/buttonStyleSmall"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:drawableLeft="#drawable/handshake"
android:layout_marginRight="55dip"
android:layout_marginLeft="55dip"
android:drawablePadding="-25dp"
android:paddingLeft="10dip"
android:paddingRight="50dip"
android:layout_marginTop="10dip"
android:background="#drawable/curvedplanebutton"
android:textColor="#drawable/button_text_color"
android:text="Utility Bills Payment"/>
</LinearLayout>
try this
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#android:drawable/btn_star_big_on"
android:text="Drawable left">
Button>
For more info go to this link
http://izvornikod.com/Blog/tabid/82/EntryId/8/Creating-Android-button-with-image-and-text-using-relative-layout.aspx
I think you made your button to Complex,
Just use below code and let me know what happen..
<Button android:id="#+id/btnUtilitybillpayments"
style="?android:attr/buttonStyleSmall"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_marginRight="55dip"
android:layout_marginLeft="55dip"
android:drawableLeft="#drawable/handshake"
android:layout_marginTop="10dip"
android:gravity="left"
android:paddingLeft="20dip"
android:background="#drawable/curvedplanebutton"
android:textColor="#drawable/button_text_color"
android:text="Utility Bills Payment"/>
As I have also doubt on layout_margin attributes of your Button. If it doesn't work then try to remove
android:layout_marginRight="55dip"
android:layout_marginLeft="55dip"
Some thing like this.
<Button
android:id="#+id/btnUtilitybillpayments"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/curvedplanebutton"
android:drawableLeft="#drawable/handshake"
android:gravity="left|center"
android:text="Utility Bills Payment"
android:textColor="#drawable/button_text_color" />
A more suitable approach is by making the button as a 9patch image. That way, you can define where the text should be by patching the right and bottom side. And there wont be any need for such complex button.
You can go here for more information-
http://developer.android.com/tools/help/draw9patch.html

how do i add image in button? image with text

hi i want to create image button like this way http://imgur.com/sshdf in this url how do i create button like this? half image half text? please help me i wanna create exactly same button
<Button android:id="#+id/MyAccountMiniStatement"
style="?android:attr/buttonStyleSmall"
android:layout_height="25dip"
android:layout_width="fill_parent"
android:layout_marginRight="10dip"
android:layout_marginLeft="10dip"
android:background="#drawable/curvedplanebutton"
android:textColor="#drawable/button_text_color"
android:layout_marginTop="10dip"
android:text="Mini Statement"/>
Add this attribute to the button android:drawableLeft="#drawable/ic_launcher"
Something like this,
<Button android:id="#+id/MyAccountMiniStatement"
style="?android:attr/buttonStyleSmall"
android:layout_height="25dip"
android:layout_width="fill_parent"
android:layout_marginRight="10dip"
android:layout_marginLeft="10dip"
android:drawableLeft="#drawable/ic_launcher"
android:background="#drawable/curvedplanebutton"
android:textColor="#drawable/button_text_color"
android:layout_marginTop="10dip"
android:text="Mini Statement"/>
By providing the drawable Left, the icon will be placed to the left side of the text and also you can use the background attribute to give the white background to your whole button.
Why don't you Use ImageBUtton, I think that will be good for you
<ImageButton
android:id="#+id/ImageButton01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/album_icon"
android:background="#drawable/round_button" />
Solution is to use CompoundDrawable.
Some attributes for Button and TextView:
1. android:drawableLeft
2. android:drawableTop
3. android:drawableRight
4. android:drawableBottom
And yes use android:drawablePadding to give padding between your text and image.
Use Textview and for text and android:drawableTop="#drawable/ic_launcher" for image in textview.
So after using this you can see that your textview is containing image also.
Try below code instead of your button code.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/ic_launcher"
android:gravity="center"
android:text="Hello" />
Also you can add drawable to any side.
Top, bottom,right,left.
android:drawableBottom="#drawable/ic_launcher"
android:drawableTop="#drawable/ic_launcher"
android:drawableRight="#drawable/ic_launcher"
android:drawableLeft="#drawable/ic_launcher"

Categories

Resources