Android Custom EditText text alignment bottom - android

I created a custom drawable for the background of an EditText. I need the text to be left and bottom aligned. It renders fine on screen but the text is not aligned to the right nor the bottom of the drawable. I also tried gravity:bottom and tried setting the padding on top in hopes it would move it down. Is there anything else I can do?

The right and bottom lines define the content area.
The line you draw on the right spans the top half of your image. That's why the text won't align to the bottom.
You should draw a slightly longer line.
Check out the image used by default. (I changed it to blue here though).
This will give the same result you are having. The text won't be aligned to the bottom.
Now if I extend the right line to the bottom, I would obtain the below image.
This will give you the expected result.

Related

How to constraint a view to overlap another view in RelativeLayout

I am overlapping an ImageView on top of a View in a RelativeLayout.
something like this:
1
Where the middle white circle(ImageView) is overlapping the white vertical border(View).
But for some reason I am not managing to constraint the circle above the z position of the white border. and if the border moves say to the right side of the screen, I want the circle to move there too. but instead the circle always remains in the center regardless to the position of the border.
How do I this in a RelativeLayout?
T.I.A
You can make like:
AlignLeftOf the border
Then code: circle.translationX( circle_width/2)
(and a bit of justification, it should be good)

Buttons text is not aligned any more after changing the BackgroundDrawable

i am changing my buttons' backgroundDrawable programaticaly:
myButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.card_button_blue));
After changing the background, the text in the button is not aligned any more like it was before changing the background.
(source: dsliga.eu)
target SDK version is 10.
Thanks.
Looks like the setText() method messes up the alignment. After changing the text, re-applying the gravity and padding did the job:
myButton.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
myButton.setPadding(12, 12, 12, 12);
Since you are using a 9patch, you need to specify with bottom and right side lines where the data is inside your drawing, you probably did not draw a full line at the bottom, and right side of the 9patch drawing
this is why the text inside your button stopped being centered, because the bounds of the 9patch are NOT what you think they are
your 9patch should (normally), leave only 1 pixel at the top and bottom of the right side line, and 1 pixel at the left and right of the bottom line
redraw the 9patch, remove the gravity and padding code, and see if it works
see below image

relativelayout space between its elements when background image is present

I have a relative layout with background image (9patch). I have set this image as background to the layout using xml. When I add another relative layout which has buttons and textviews, there is little space left before the new layout. I didnt set any padding. I also tried by setting padding top to 0. If i remove the background image the alignment will be proper with no space left on top of new layout. I have also tried by setting match parent and fill parent in new layout but still the space remains on top of it. The space left is very little like 3dp-5dp.
can someone suggest about this issue pls.
EDIT : space is on top of the new layout horizontally and i have tried setting gravity to top and also top left.
The black pixels on the top and left define the stretch area of the 9-patch, while the pixels on the bottom and right define the fill area. My guess is that you have a fill area defined that does not cover the entire right and bottom edges.
Here's a good guide.

Vertically centering overlarge text in Android buttons

Android, Button view. The Button size is 38x38dp, text size is 20dp (just one + character worth of text). Gravity is set to center|center_vertically.
The text is NOT centered vertically. According to Android's internal accounting, the text is too large for the specified button size, so the text is placed with its top aligned with the top padding, and its bottom cut off. That's not what I want; I want the text to be cut evenly on the top and on the bottom. In other words, vertically centered. The plus character, since it takes less than a full-sized character cell, won't suffer from that.
It's Gravity that I set, not Layout gravity. I know the difference.
Any ideas how to make vertical centering work in such conditions, short of overriding draw()?
Try adding android:includeFontPadding="false" to the Button view.
Some have suggested adding android:baselineAligned="false" to the container for similar problems but it didn't do anything for me.

Android padding problem

:) I'm having the following problem: I have a view and i want to add borders to it. What I'm currently trying to do is to set padding to the view (padding from all the sides) and set background color to it which will fill the padding. The thing is that it seems to me that it's possible to set padding either only from top and left or from bottom and right but not from all of them together. I.e if i write
view.setPadding(border,border,border,border)
this will set padding only from top and left. In order to set padding from bottom and right I have to write:
view.setPadding(-border,-border,0,0)
which won't leave left and top padding and so on. If I try to use margin it moves the whole block(the view + the padding area), but not only the view, so this doesn't seem to work either. Any ideas on how to do it without having to use a wrapping layout? Thanks!
What exactly happens when you use the first example?
The four int parameters for setPadding() are for left, top, right, and bottom, respectively. So, calling setPadding(4, 5, 6, 7) should give you 4 pixels of space for the left edge, 5 for the top, 6 for the right, and 7 for the bottom. What result are you getting when you do this? Can you show a screenshot?
What is the content of your view? If it's an image or something similar, perhaps it's not being centered or scaled properly. Try calling setGravity(CENTER);.

Categories

Resources