问题
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 question is how can I limit the editText lines? I don't have any idea for this.
UPDATE
I want to create new note page when cursor reached the last line.
回答1:
I Found the solution, thank everyone for the response.
My solution is:
int lineHeight = getLineHeight();
int height = getHeight();
int maximumLines = height / lineHeight();
回答2:
Check your screen size and put lines acording the height.
Display display = getWindowManager().getDefaultDisplay();
int height = display.getHeight();
//Calculate the lines with the height proportion
edittext.setMaxLines(lines);
回答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
回答4:
You can get screen size in pixel by writing following code.
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = 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
回答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.
来源:https://stackoverflow.com/questions/42294307/set-limitation-for-edittext-height-and-maximum-lines-according-to-the-screen-siz