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 :
Related
I need to get a border on the base of my android text view, it should look something like the count down -1:29 timer. I know I can create a image and put it on the background, but I need it to be a layout xml kinda thingy so that it adjusts with size of the text within for all phones.
Use a 9-patch image that can stretch horizontal and place it as a background. That is all you need.
I am trying to achieve exactly something like this
- a text view on left and a button to its right
- Button should be wrap_text
- textedit should occupy the remaining space
If you carefully see the image in the image the buttons left curved border are hiding under the text view.
I am using relative layout to adjust the button height according to this
How to get a button's height to match another element's height?
But I am unable to hide the left portion of the button.
Actually the Button isn't hidden under the EditText.
They used custom background for that button, which is 9 patch png image. You can achieve this by providing your 9 patch images for both EditText and Button with 0 margin between them.
Here is a nice tutorial about using 9 patch png.
Another post to consider is Buttons with (niceley) stretched background.
add android:layout_marginLeft="-10dp" to the button
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.
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.
i want to make a breadcrumb for my android app.
In breadcrumb on the left there is an imagebutton with arrow border. On the right there is a text title. When user tap on imagebutton, application performs specific task.
So, can you help me to create imagebutton with arrow border like in attach image?
Thank you.
I'm not 100% sure what you mean by an Arrow Border, but you cannot (as far as I know) set borders to any views in Android.
There are two options you could go for:
Make an outer View to surround the View you want a border on. Then set the background of the outer border to an arrow background.
Use a Nine Patch.
I would recommend a nine patch for this personally.
Edit: I noticed you wanted a border on an image. That could be an issue with nine patch unless you integrate the border into the image, which defeats the purpose.