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.
Related
I would like to have my 2-line text view in android-xml centered horizontally with the smallest width necessary. At the moment it's like the first line is completely filled and the second with the rest of the words.
Does anyone know how to achieve that both lines are filled kind of equally? Below are 2 images, the first showing the default multi-line text view, the second what I would like to achieve. As you can see, the second image requires much less width than the first and is more in the center of the view.
Thanks in advance!
Try setting android:breakStrategy attribute of textView to balanced
android:breakStrategy="balanced"
Add this line to your textView's xml code, this will balance the lines.
How do I make a Button so that when I put part of it out of bounds the program doesn't just cut the parts of it that aren't inbound. What I mean is this.This is a rotating view, the rectangles are rotating around the circle, but since I put 2 of the buttons partially out of bound their parts get cut off. Is there a quick fix for this?
(If programmatical fix is necessary I am writing in Kotlin)
The reason this is happening is because the RelativeLayout in which you're adding these four Views (buttons), has the width of screen's width. You need to increase its width to contain both the left and right buttons completely. Then, when you rotate the RelativeLayout, the buttons will be visible.
For testing purpose, try giving this width to RelativeLayout
<RelativeLayout
android:layout_width = "1000dp"
android:layout_height = "1000dp">
<!--Your buttons here-->
</RelativeLayout>
See if this works out. If it does, then you'll have to calculate the width of RelativeLayout programmatically.
I have a TextView that can have a few different values, and is updated runtime (in Java code).
However, I need this TextView to retain its center point, so that when the text in that TextView is updated, it is always center justified. It should be centered around a point which is not the center of the screen or anything else, so setting gravity only will not help.
As the values that it may contain are already defined, I could try with the longest one first, position it to the correct top left position and set its gravity to center. In this case every shorter in length text should fit correctly.
However, I would like to know if there is better approach, for cases when the values are not known beforehand.
This TextView is placed below an ImageView and it could take the whole screen width (nothing else is placed left or right to it).
Note: I guess it could be also possible to position it every time to a new X axis position, whenever the text is changed, but I don't think it is a nice solution at all.
Set the android:layout_width to match_parent and set android:gravity to center_horizontal.
This way the View is stretched all the way horizontally, and the content (the text) will be centered. If the content changes, it will still be centered.
One thing that many people don't realize is the difference between android:gravity and android:layout_gravity. The first one defines the alignment of the content inside itself, the other one defines alignment of itself relative to its parent.
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.
I have 2 textviews per horizontal linearlayout row on two rows. All the views are set as 0dp width and weight 1. They all have the same font and text size etc.
The views on the left side are gravity aligned left and the two on the right are gravity aligned right.
When both textviews text length overflow android always gives precedence to the textview on the right and ellipse the views on the left.
Is there a method that can be used to control which view ellipses when both views on the same row would not fit.
Ideally I want the views on the right to ellipse in favor of those on the left. Or failing that make them ellipse evenly per row.
thanks
i don't think there is a feature of order of the views to manage how they are measured.
you can customize the linearLayout by extending it in order to support this feature , but this is too hardcore for this task .
i would suggest putting the problematic views (those that take too much space and you don't with them to take too much space) into a new layout , and set its width to match_parent .
this way , it should take the rest of the space at the end of the measurements of the other views ,