I have a huge string which I have to truncate at one point, As I have to run the code in different devices with different screen sizes, problem arises with no. of lines per view in different devices. for this, obviously I should not use any methods like setMaxLength() but whereever in the the Internet I see the method every one is prescribing to set no. of lines, which is not suitable for my case.
Please some one prescribe me a procedure to truncate the text dynamically but not according to the number of lines.
If you want to truncate and not wrap the text, you could consider using
setEllipsize.
Related
Is there any way to change the layout of your app based on what text size the phone is set to? I know you can set your text so it will be static (stay the same size) but I've had some users complain because the app doesn't look good because of the large text. These are mainly older people who need the large text and it would be nice if there was an easy way to accomplish this without splitting one activity into two separate ones so they could still use it. Any ideas?
Is it possible to develop something like this in Android?:
Note that the length of any of the three text components is dynamic.
I pretend to receive a first String (that might be multilined) then an input field for the user, and finally, another String (can also be multilined). I want them all to seem like they belong to the same sentence.
I'm not asking for the full code, just some clues.
Thanks in advance.
I finally achieve it by using FrameLayouts and with the help of this posts:
Android: measureText() Return Pixels Based on Scaled Pixels
Get current visible text in textview
How to find android TextView number of characters per line?
I am trying to have a custom EditText based on the background that i am using for. The Background image has some spaces between the entry areas so i need to have some space between the characters(kerning) to fit them right in. So for example after every character the user enters, i need to put 4 whitespace after that.
I couldn't find any solution for this on the net so far, some people suggested TextWatcher, but i couldn't manage to make it work as i want it too.
Can someone help me about it?
Thanks
I have you considered using a custom font? Some font types are made to stretch out or shrink or have empty spaces. With so many different fonts available online, you can definitely find something. You can also make your own with a software. It might be time consuming if you start the lettering from scratch. I'm not 100% sure if it'll fit exactly to your background, but it's idea that you can consider.
If it doesn't fit, I supposed you can always customized the background to fix your font too. Here's the code for those who might want to use custom fonts in their app too.
Typeface myfont = Typeface.createFromAsset(getAssets(),
"fonts/Blocks2.ttf");
myeditText.setTypeface(myfont);
The font is in the asset folder under another folder called fonts.
This question is related to How to change letter spacing in a Textview?
As shown at this issue: android format edittext to display spaces after every 4 characters a solution might be to insert spaces with Java code...
You need to use TextWatcher to achieve visual purpose spaces.
And use any simply split string by space logic to join it back or loop
through the entire string per character wise and eliminate (char) 32
from the string
As far as i know actual character spacing is not possible, though i'd love to use that myself as well.
Another option might be to use a custom font with the character spacing included.
Is there a way to limit the input length of a Android edit text field using some sort of physical parameters (i.e. inches, pixels, etc.) I do not want to limit the field by character number.
Thanks for the help!
you can use android:maxWidth="100dp" but that is going to set the max width of the View itself, and will not affect how many characters are allowed to be typed into it.
I do not beleive there is an easy way to accomplish what you want. The only thing I can think of is use a TextWatcher and dynamically determine how many characters will fit in the the size that you are wanting (which will be different for different devices). That is still basically "limiting the field by character number" though which you state you don't want to do.
Can you elaborate on why you are wanting to do this? Perhaps there is a better way to solve the overall challenge that you are facing.
You want to add a text changed listener (TextWatcher). In your listener you'll need to measure the size of the font, and the pixel density of the screen, and the number of characters. Multiply all of those together and you should know how physically long the text is (with a few caveats).
Having said that, this seems like a weird restriction and I'm not sure why you want this. Every device is going to have a different screen size, so measuring your interface in inches is typically a bad idea.
You could find how how many M's will fit in the printed form and then use EditText.SetMaxEms To make sure the input will be printable on the form.
Try this on your EditText
android:maxLength="10"
How can I determine the number of visible characters that a TextView can display. For example if I change the orientation this number may change. If I change the resolution then also the number of visible characters changes.
Thanks in advance
Thank you for your answer.
Currently I am developing a small text based game to become acquainted with the Android API. For that reason I need to know exactly how much characters can be displayed in the visible area of a TextView widget. I saw an example of Paint but wanted to know if there are better solutions.
Ideally, you design your GUI such that it does not matter. For example, you can use android:ellipsize to deal with strings that are too long for the available space.
There are classes in the 2D drawing APIs (e.g., Paint) that seem to be tied into this, but it does not look like much fun.
You can use ellipsize property but there has been a bug that has been filed on the same
http://code.google.com/p/android/issues/detail?id=2254
On the bottom of this page you could find an alternate approach which can draw exactly the number of lines on a given space...