Resize Image within a Button - android

Is there any way of resizing an image in a button? The image source is from the drawables folder. I want to have the following layout for the button.
I know that we can use the android:drawableLeft XML tag for the button, but the image is crossing the boundary of the button and thus getting cut off on all sides.
I want my entire image to be in within "Image here" slot from the above depicted layout. How can I achieve this?

If you are using a default button, use the default padding (don't set the padding values) and the image should not cross the boundary.
Alternatively for finer control you can place an ImageView and TextView within a layout (e.g. LinearLayout) and set the layout's style="#android:style/Widget.Button".

Related

How to 9-patch so icon always stick with centered text

Basically, I wanted to have a button where text and icon stay in the middle of the button at all times. The Button has match_parent width and center gravity. I tried to use drawableLeft but that put icon on the left most of the Button and not next to the text.
So I'm trying to create 9-patch image as shown in the image above. Basically, I want all the text to stay in blue box with the cyan rounded rectangle (icon) next to it. The stretchable area is in red. However I just can't make it as the content area always overlap the icon.
Is this possible with 9-patch? Or should I wrap Layout around the TextView and use that as a button instead?
By the way, the included image is just to show what I plan to do. The actual image will be in other colors and without all the red.
When you create a nine-patch image, you put some black lines on the right and bottom of the image. These lines define the region that will be use to place the content inside of your image.
Here is an example :
It will look like this :

How to place an image on top of another image in Android XML?

I am creating an app which is a guide. I have a photograph showing an example, but I need to know, how can I make certain parts of the images clickable, to go to another activity to show more details about that thing.
Or have an image (which will be clicked) on top of the base image?
Thanks
have an image (which will be clicked) on top of the base image?
1 -
Can set the Background of Linear layout and add imageView in center of parent.
or
2- Use relative layout with tow image Views
You can split your main image on rectangular parts, then put them as ImageViews using RelativeLayout or TableLayout (which ever fits best in your case) so their combinations looks like a single image.
On each ImageView you can set a click listener using View.setOnClickListener(View.OnClickListener l)

EditText background image - align right

I'm trying to create an EditText that has the following background images (aligned right) when a user inputs valid/invalid text:
How can I achieve this in Android? I've tried setting the background image using:
editText.setBackgroundResource(R.id.icon_tick), but when I do this, the whole image gets stretched to fit the EditText.
editText.setCompoundDrawables(left, top, right, bottom) where left, top, right and bottom are either drawables or null.
Why does it have to be a background image? Just make it a standard image and position it accordingly in your layout. Otherwise, you'll need to make a large image that actually takes up the entire background of your view (with your icons positioned where you want them). You'll also need to size this image accordingly for the various screen resolutions.
An alternative approach can also be found here:
Background Image Placement
Possible duplicate post.
You can make the drawable as nine patch image. Have some transparent area to the left of the tick mark and define it as stretchable area. That should do the trick.

How to remove the android Button Background margins?

I'm new to Android dev, I'm trying sth simple: I want to place a set of 3 buttons horizontally in a line, each with its own background PNG image. So I create a linear layout (horiz) and put three Button elements, each with a weight of 1, and set each button's Background property to some png file. The buttons' width/height is set to wrap_content.
But what I get is that the png does not cover the entire button horizontal area. Instead, the background image is scaled down and keeps some sort of margin from the button view outline as shown in the visual designer. This also shows up in the emu. I tried forcing 0 in the layout's padding/margin - nada.
any idea on how to actually get the background image of a button to cover the button's background??
tnx
I believe you would need to make a new 9-patch, as that small margin is saved into the button image itself.
Try negative values for the buttons layout_margin.

Android writing over image in button

If I have a custom image can I write over it, will it always write to the center of the button image? Ie will setText on image always right to center of the image provided or do I need to do something to have this effect? Thanks Also is it better to use ImageButton or set Image as background of Button? and write over it that way. I want to use 3d images and write on top of them in black text.
I don't know if there is a preformance difference for using image button of a normal button, but I'd imagine that and image button will work better. Albiet I always just use a normal button and setBackground(...). Also if you want to set the text to always be in the middle, use android:gravity="center" in the layout file.

Categories

Resources