我有这样的布局:
<TextView
android:id="@+id/txtAyaat"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:textSize="20sp"
android:bufferType="spannable"/>
<Button
android:id="@+id/btnReveal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="@string/reveal"/>
<LinearLayout android:id="@+id/pnlDifficultyButtons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:visibility="gone">
<Button
android:id="@+id/btnAgain"
android:layout_width="0dp"
android:layout_weight="0.25"
android:layout_height="wrap_content"
android:text="@string/again"/>
<Button
android:id="@+id/btnHard"
android:layout_width="0dp"
android:layout_weight="0.25"
android:layout_height="wrap_content"
android:text="@string/hard"/>
<Button
android:id="@+id/btnGood"
android:layout_width="0dp"
android:layout_weight="0.25"
android:layout_height="wrap_content"
android:text="@string/good"/>
<Button
android:id="@+id/btnEasy"
android:layout_width="0dp"
android:layout_weight="0.25"
android:layout_height="wrap_content"
android:text="@string/easy"/>
</LinearLayout>
在片段代码中,我正在设置一些阿拉伯语文本,然后应用模糊的spannable&amp;前景色:
List<Ayah> ayaat = getTestAyaat(startAyah, endAyah);
String formattedAyaat = formatAyaatToString(ayaat);
txtAyaat.setText(formattedAyaat);
MaskFilterSpan maskSpan = new MaskFilterSpan(new BlurMaskFilter(7, BlurMaskFilter.Blur.NORMAL));
ForegroundColorSpan colorSpan = new ForegroundColorSpan(Color.GRAY);
Spannable spannableText = (Spannable)txtAyaat.getText();
int startBlurIndex = ayaat.get(0).AyahText.length();
int endBlurIndex = formattedAyaat.length() - ayaat.get(ayaat.size() - 1).AyahText.length();
spannableText.setSpan(maskSpan, startBlurIndex, endBlurIndex, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
spannableText.setSpan(colorSpan, startBlurIndex, endBlurIndex, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
Typeface meFont = Typefaces.get(getActivity(), "myfont.ttf");
txtAyaat.setTypeface(meFont);
我得到奇怪的结果,当我模糊整个事情它很好,但当我想模糊中间的一切时它会弄乱: