I have 4 TextViews placed horizontally filling all the width of the screen, and each TextView with the same horizontal width . Depending on the device's screen the total width is diferent. I want to change the textsize to fill each TextView horizontally but in a manner that the text fits. Is there any way to do this?? Thx
I think that this link could help you immensly as it is very similar. You may have to SET your widths static based upon you screen width then continue to adjust your font size until the vertical direction fits for each textview.
Calculate text size according to width of text area
Related
Problem : While adding text to a text view in android , when text is long enough to make textview height greater than screen, the textview is only increasing its height up to the screen height and not going beyond the screen.
Requirement: To increase the height of text view according to the text content .
Is it possible to change the height of a text view at runtime?
EDIT
Even though I change the height of TV (greater than height of screen) in XML
still my TV height is not exceeding screen height.
EDIT 2
I achieved this by drawing the TextView using canvas. I am not sure how efficient this is.
I have a TextView that I want to have 1/8 of the whole screen, and dp just works to get half of the height but how do I get the 4 TextView's to each share the bottom half of the screen equally?
Right now they share the height equally, but the ones on the left are wider than the ones on the right.
Inside of your RelativeLayout you need to make a horizontal LinearLayout just for these TextView's. Then to make them all take up an equal amount of space, assign an equal weight to them all with weight="1".
If you want a TextView to take up more or less space than the others, just assign a proportionate weight to it. For example if you have 4 views and want the first one to take up 1/2 of the space and the other 3 to share the rest equally, set the weight of the first view to 3 and the others to 1.
You can't with a relative layout- consider a PercentRelativeLayout
I have a group of Buttons which have varying widths, and I'm inserting them programmatically into a RelativeLayout (horizontal orientation). I'm trying to scale the width of the buttons so that they take up the entire width of the visible screen. The important thing is, the buttons' widths should remain proportionally the same to each other; just stretched or shrunk to take up the entire screen width.
I'm setting the initial width of each button to a discrete, unrelated int value. In most cases, the group of buttons only take up part of the screen width. I'd like to stretch the buttons' widths, to take up the entire screen width, while retaining the button widths' proportions, relative to each other.
Can someone give me some assistance in calculating the new, adjusted widths of the buttons? I have no problem getting the screen width in pixels, and I can also easily get the total widths (in pixels) of all the buttons. I just need to scale each buttons' width, and I have to do it programmatically; not in the xml. TIA.
Figured it out (derp). Just set each button's width to (original button width) * ((screen width pixels) / (total buttons' widths)). The trick was getting an actual decimal value out of the quotient above.
I've been digging around for a while about this issue. In my layout, I have a textview. How do I make the width of my textview's width half of the screen's physical width? Can I do it in the xml layout directly or I should have a function in the java code,which gets the physical size and set the textview's size one half of that?
I don't care abou the resolution.
Thanks in advance!
You should use the layout_wheight attribute for yout TextView:
Android:layout_width="0dp"
Android:layout_weight=1
Use the same property (and same weight) on the layout you want to place on the side of your TextView, they will have both the same size = 1/2 of your physical screen.
I have a few buttons I want to display in a row in a decision tree. I'm trying to get the buttons in each row of the tree to be the same size. But the buttons have different text. Some have a couple words and some have a sentence. Is there a way I can get the buttons to all be the same size and all maintain the same width to height (4:3) ratio?
I can get the heights the same using fill parent on the button heights while having the parent row layout_height set to wrap_content. How can I get the width of the buttons to be the same size while maintaining a 4:3 width to height ratio. (The width to height ratio constraint is so I don't end up with really tall and thin buttons, which would look silly)
Anyone have any suggestions?
Edit:
I just saw this link which is kinda what I am looking for: Scaling layout with invariant aspect ratio in Android
My problem with this is that it will inflate all the buttons and introduce a lot of empty space around the text inside.
If I could find a way to incrementally increase the width or height (whichever is smaller) of the button and then resize it so it re-"wraps_content", then this could work. Anyone know how to re-wrap the content?
If you are able to get the same height for all you can use android:layout_weight="1" for all buttons and put android:layout_width="0dip" so all buttons will have same width