I have a TextView which has a SpannableString inside it to highlight searched terms. Like so :

<TextView android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/textBox"
android:textSize="16sp"
android:paddingTop="10dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:lineSpacingExtra="5dp"
android:textColor="@color/TextGray"/>
As can be seen I am using android:lineSpacingExtra to give the lines a nice spacing, however it is causing the SpannableString background to be too tall. I would like to keep the spacing between the lines but make the SpannableString shorter.
How is this possible?
You can create your own span by extending ReplacementSpan. In
drawmethod, you can take into account thefontSpacingwhich you can get fromPaintparameter.Like this:
You can use it like this:
I couldn't much test it but you can improve it.