Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get max lines of Text

Tags:

People also ask

How do I limit text lines in CSS?

The easiest way to limit text to n lines is to use line-clamp . N can be any positive number, but it will be two or three lines most of the time. On my blog, I'm using line-clamp in all post-type components to ensure that it will have the same height as siblings.

How do you check if a Textview's text exceeds the max lines?

text_view. post(new Runnable() { @Override public void run() { if (text_view. getLineCount() < text_view. getMaxLines()) { // do stuff } } });


How to get the maximum number of lines that can be written in TextView? I tried this:

DisplayMetrics metrics = new DisplayMetrics ();
getWindowManager (). getDefaultDisplay (). getMetrics (metrics);
float width = metrics.widthPixels;
float height = metrics.heightPixels;

int lines = (int) (height / textView.getLineHeight ());

System.out.println (lines);

However, this variant gives the wrong information.