FarshidABZ
FarshidABZ

Reputation: 4143

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 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.

Upvotes: 3

Views: 2941

Answers (5)

FarshidABZ
FarshidABZ

Reputation: 4143

I Found the solution, thank everyone for the response.

My solution is:

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

Upvotes: 2

Lym Zoy
Lym Zoy

Reputation: 1011

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.

Upvotes: 0

Pankaj Lilan
Pankaj Lilan

Reputation: 4453

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

Upvotes: 0

jaibatrik
jaibatrik

Reputation: 7543

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

Upvotes: 0

Roger RV
Roger RV

Reputation: 134

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);

Upvotes: 0

Related Questions