Android : Getting extra space while using SpanningString

on Tuesday, April 14, 2015


I am creating a CustomView. I need a string to be a spannable string, to change the colour of a part of the string. The code compiles, but there is a long space between the string and the part that is to be coloured.


Here is the code :



String string = mStat1 + "" + mStatValue1;
SpannableString spannableString = new SpannableString(string);
if(mStatValue1<=0) {
spannableString.setSpan(new ForegroundColorSpan(Color.rgb(183,108,100)), mStat1.length(), string.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
else {
spannableString.setSpan(new ForegroundColorSpan(Color.rgb(117,205,132)), mStat1.length(), string.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
TextPaint textPaint = createTextPaint(mTextColor, mStatSize, Paint.Align.CENTER);
mDynamicLayout = new DynamicLayout(spannableString, textPaint, mWidthPix/2, Layout.Alignment.ALIGN_NORMAL, 0.0f, 0.0f, false);


Here is the image of the view that i get :


enter image description here


I need to remove the gap between the coloured part of the string and the remaining string. Thanks.


0 comments:

Post a Comment