Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Spannable Line Height
    primarykey
    data
    text
    <p>I have been trying to figure this one out for the last couple of days now, and have had no success...</p> <p>I'm learning android right now, and am currently creating a calculator with history as my learning project. I have a TextView that is responsible for displaying all history... I'm using a digital font that looks like a calculator font, but this only looks good for digits and decimals and comma's. I want all operators to be highlighted and in a different font (Arial Narrow at the moment). I have been able to get this to work beautifully using a spannable string where I'm specifying a font color as well as a font using a CustomTypeFaceSpan class to apply my custom fonts.</p> <p>The problem... When I mix the Typefaces, there seems to be an issue with the line height, so I found <a href="https://stackoverflow.com/questions/11111129/android-textview-individual-line-spacing-for-each-line" title="Post 11111129">this post</a> which demonstrates using another custom defined class to apply a line height to each added line of spannable text:</p> <pre><code>public class CustomLineHeightSpan implements LineHeightSpan{ private final int height; public CustomLineHeightSpan(int height){ this.height = height; } @Override public void chooseHeight(CharSequence text, int start, int end, int spanstartv, int v, FontMetricsInt fm) { fm.bottom += height; fm.descent += height; } } </code></pre> <p>This does not seem to work, and I can not figure out why. If I don't apply the different typefaces, then it displays as expected with no space above the first line, and about 5px spacing between lines. When I apply the alternate typefaces, there is a space of about 10 to 15px above the first line of text and the line spacing is about the same 10 to 15px.</p> <p>There is no difference in the font size, only the typeface. What am I missing. I implemented the CustomLineHeightSpan which implements LineHeightSpan and overrides the chooseHeight method. I call it like so:</p> <p>WordtoSpan.setSpan(new CustomLineHeightSpan(10), operatorPositions.get(ii), operatorPositions.get(ii) + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);</p> <p>It does not seem to matter what I put in the call to CustomLineHeightSpan. Nothing changes...</p> <p>Anybody have any idea what I'm missing... I'm sure it's an "I can't believe I missed that" answer, but can't seem to figure it out at the moment.</p> <p>Thanks for the help guys :-)</p>
    singulars
    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.
 

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