Limited WRAP_CONTENT for edittext - android

I want that when my edittext is empty it's height is 40px, i.e., it takes space of only one line. And when text is typed the height increases. It should function more like the WRAP_CONTENT on its height, but I want that once it reaches the height of (5*40px) or 200px, i.e., space of 5 lines. It doesn't increases anymore. It acts as if it's height is fixed 200px. How can I access this type of height feature.
Please try to help by providing Programmatic reference rather than XML reference. Thanks in advance...

You should check this question out. It has exactly what you need. Next time while asking a question, please do a little bit research.
Set limitation for EditText height and Maximum lines
Also, there's a tag called android:maxLines="int"or editText.setMaxLines(int numOfLines) method if you want that to set how much the EditText will stretch. It'll do exactly what you need to do.

Related

TextView Not Displaying After Large Scale Up

I am working on a project that involves a letter filling up most of the height of the screen. At this point, the height of the letter is supposed to be 428 Pixels. The height of my screen is well over this, the layout (although a fragment) has ample room to fit the letter, and both the fragment layout and underlying layout are set to match_parent. For the textview itself, I have it centerInParent = true Trust me, I've been doing this a while so I know everything is correct as far as initialization goes, I just can't figure out why the letter wont appear! Oh, I should also note that although the screen can hold that size of a letter, it is tight (talking about approximately 50 pixels above and below), and that the entire activity and layout is set to a FullScreen theme, because I assumed it would give it more usable space. Any ideas? Thanks everyone!
EDIT: The total number of pixels I have in my display height of the monitor is 721, the letter takes up 428 pixels, after subtracting a few default-sized buttonss at the button that leaves me with about 260 pixels of free space. And as I mentioned there is no actionBar.
I found that I had to convert the textView using this code: txt.setLayerType(View.LAYER_TYPE_SOFTWARE, null); Hope this helps!

Limiting an EditText in Android by text width instead of number of characters

I am trying to fit an EditText into different ImageView templates. For each template, I want to restrict the EditText to a specific width.
For example, in one of my templates, the EditText field should fit a maximum of 300 pixels wide, so I would like to set the text width limit to 300 pixels.
However, I cannot restrict the length by character length because, typing:
"iiiiiii" is not the same width as "wwwwwwwwww."
Would anyone happen to have a solution to this? Thanks.
You could use a textWatcher. This would have a method called onTextChanged(). You could override this to get the length. Once this is done, you could alter the length of the textView itself.
http://www.rqna.net/qna/tssiw-android-edittext-limit-string-length-not-by-characters.html
That guy answered your question with probably the best answer 2 months ago...
You can achieve something similar with android:paddingRight through xml

whats better, giving hard coded height or using weight parameter to set View parameters..?

I usually give fixed height in order to avoid views getting overlapped on orientation change, But is giving weight is better than this..?, share it if there are better ways to give LayoutParameter.
Thank you.
It completely depends on situations, like when my view should cover a part of width and height available on screen, then I would opt for weight and when it should be fixed in dimensions irrespective of width, height then use fixed layout co-ordinates.

Android: Height of EditText widget

I need to make an EditText smaller in height than the default wrap_content height.
Reducing the layout height property doesn't work. Reducing the text size property doesn't work. Reducing the padding doesn't work. All these attempts have produced horrible visual effects.
Does anyone please know how to do this successfully ?
It's not possible unless recreating the ui pictures.

Calculating Android TextView's text capacity

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.

Categories

Resources