I have TextView with height and width as fill parent. Is it possible to find out how many characters can this layout hold?
Do you mean how many characters can be entered into the textview and still be fully visible without scrolling? For proportional fonts, that will depend on the specific characters typed, including where the line break opportunities are. I don't think there's a simple way to compute that.
Related
I am trying to find a library or a simple trick to fix the width of each letter in an EditText so that the dashed lines on the background match exactly the number in the EditText. You can see the photo for the desired effect.
Using various widget i.e. Edittext in a row with the text style to underline will helps to get these type of design else i don't think there is any hard and fast rule or tricks.
There is no simple way of doing this, especially not when aligning to a given background, because many factors such as display size and density can change the relative positioning of the EditText. You could perhaps work around this limitation by drawing the white lines under each digit yourself, using a custom font or underlining and separating the digits with a space. See this question for a more detailed explanation on the limitations and possibile solutions concerning letter spacing.
I only know that, font monospace will be useful. Other fonts set different widths to each character.
If I have a text in a button that has match_parent, is it possible to make the textSize as big as possible without cropping the text? Preferably in XML and with a maximum setting so it doesn't become too big. In other words I'd like it to make it just fit if it would split a long word, otherwise stick to the preset size.
This way, but it does not look clearly in my opinion you should to try to change your design to avoid this requirement
Is there some way to use StaticLayout without doing automatic word wrapping? If the text includes newlines I want them to break up the paragraphs, but I don't want it wrap at a given width. It's not giving sane results, especially with Center/Right aligned text.
Is there a way to simply turn off the auto-wrapping on StaticLayout?
More details. I use getDesiredWidth to calculate a width and then use this as the wrap width for a new StaticLayout. This prevents auto-wrapping, but it also seems to turn off explicit wrapping as. GetLineCount returns 1 for text that actually has multiple-lines.
I have a function that generates a random number. Then, I place the number in a TextView. When the number is a single digit, it fills the TextView perfectly, but when the number is two digits or more, it only shows a single digit because the text size is huge.
How do I automatically fit the text size to the TextView? Something like reduce the text size so that all the number will be shown in the TextView.
I don't have enough reputation to comment so I must abuse an answer. No need to reduce the number's size. Just make sure the TextView is set to wrap_context in the layout:width property and also possibly the layout:height property, that should fix your formatting problem.
for practice I am writing an activity that takes a string from a local DB and puts it into a listView. However the string's are of different length, ranging from a couple of characters, to a couple of sentences. Write now I can take them and place them in a listView but, not all of the strings fit. I was curious if/how you can dynamically choose the height of each part of the list view so that the entire string can fit in it.
Just make sure your list item layout is using wrap_content for its layout_height attribute. If you're using a fixed height, it won't scale to fit larger strings. If you want the lists a specific size except for in situations as mentioned, you can also add a android:minHeight attribute as well with the dimension you want as standard.
Also, make sure your TextView is set to multiline (attribute android:singleLine="false").