Skip to content Skip to sidebar Skip to footer

Set Limitation For Edittext Height And Maximum Lines According To The Screen Size

I have a notebook application and I want to limit my editText maximum lines according to the screen height. for example 40 lines in nexus-6p and 35 lines in nexus5 and etc. So my q

Solution 1:

I Found the solution, thank everyone for the response.

My solution is:

int lineHeight = getLineHeight();
int height = getHeight();
int maximumLines = height / lineHeight();

Solution 2:

Check your screen size and put lines acording the height.

Displaydisplay= getWindowManager().getDefaultDisplay();
intheight= display.getHeight();

//Calculate the lines with the height proportion

edittext.setMaxLines(lines);

Solution 3:

I think you should create different layout files based on the screen dimensions. In those layout files you can change the maxLine parameter for the EditText.

Check https://developer.android.com/guide/practices/screens_support.html

Solution 4:

You can get screen size in pixel by writing following code.

Displaydisplay= getWindowManager().getDefaultDisplay();
Pointsize=newPoint();
display.getSize(size);
intwidth= size.x;
intheight= size.y;

After that you can put the condition and then assign the EditText in following way

editText.setMaxLines();

Your problem will be solved

For more details of Screen size refer the link: Supporting Multiple Screens

Solution 5:

If your EditText just contains chars, use screenSize/editText.getLineHeight(). However, if it also contains some mark-ups(like Spannable), this method will be useless and there may not be a solution.

Post a Comment for "Set Limitation For Edittext Height And Maximum Lines According To The Screen Size"