Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have found a "cheeky" solution to the problem of measuring the height of the text in a MULTILINE TextView <strong>:</strong>-</p> <pre><code>//Calculate the height of the text in the MULTILINE TextView int textHeight = textView.getLineCount() * textView.getLineHeight(); if (textHeight &gt; textViewHeight) { //Text is truncated because text height is taller than TextView height } else { //Text not truncated because text height not taller than TextView height } </code></pre> <p>However this solution has some <strong>caveats :</strong>-</p> <p>Firstly regarding getLineHeight() , markup within the text can cause individual lines to be taller or shorter than this height, and the layout may contain additional first- or last-line padding. See <a href="http://developer.android.com/reference/android/widget/TextView.html#getLineHeight()" rel="noreferrer">http://developer.android.com/reference/android/widget/TextView.html#getLineHeight()</a></p> <p>Secondly , the application needs to calculate the actual height of the TextView in pixels , and (in the case of my layout) it might not be as simple as textView.getHeight() , and calculation may vary from one layout to another layout.</p> <p>I would recommend <strong>avoiding</strong> LinearLayout because the actual pixel height of the TextView can vary depending on text content. I am using a RelativeLayout (see <a href="http://pastebin.com/KPzw5LYd" rel="noreferrer">http://pastebin.com/KPzw5LYd</a>).</p> <p>Using <em>this</em> RelativeLayout, I can calculate <em>my</em> TextView height as follows :-</p> <pre><code>//Calculate the height of the TextView for layout "http://pastebin.com/KPzw5LYd" int textViewHeight = layout1.getHeight() - button1.getHeight() - button2.getHeight(); </code></pre> <p>Hope that helps,</p> <p>Regards,</p> <p>James</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload