2017-09-07 3 views
0

私が期待したのはこれのようなものです。 enter image description here これは映画のレビューです。いくつかの言葉がストーリーを害するかもしれない場合、これらのタグで包まれます[スポイラー] [/スポイラー]。 私はスポイラーの単語の開始インデックスと終了インデックスを見つけ出し、その後MaskFilterSpanを使用してそれをぼかしました。Android SpannableStringとMaskFilterSpanを使用してTextViewの一部のテキストを期待どおりにぼかす方法はありますか?

しかし、結果は良くありません。

enter image description here

私はちょうどStrikethroughSpanまたはBackgroundColorSpanにMaskFilterSpanを交換した場合、それは完璧に動作します。 enter image description hereenter image description here

マイコード:

private void testBlurText() { 
    String text = "Alec Baldwin nailed his job; \n" + 
      "The animators nailed their job (seriously, the art style and changes were amazing);\n" + 
      "The ideas guy nailed his job ([spoiler]It's all the imagination of the kid[/spoiler]);\n" + 
      "The writers just let the story down :(([spoiler]Although at the beginning it's clear that the whole shebang is the older kid's imagination, the writers probably realised that the script was too short and so the end got changed to something that makes no sense. Why would Tim receive the kid for a second time? - unless it was all a dream...[/spoiler]).\n" + 
      "\n" + 
      "All in all, a good movie, amazing acting and animating, partly let down by a badly written ending to the story. 8/10."; 
    SpannableString spanText = new SpannableString(text); 
    List<Pair<Integer, Integer>> spoilersContainer = new ArrayList<>(); 
    getSpoilerIndex(text, 0, spoilersContainer); 
    for (Pair<Integer, Integer> pair : spoilersContainer) { 
     spanText.setSpan(new MaskFilterSpan(new BlurMaskFilter(20, BlurMaskFilter.Blur.NORMAL)), pair.first, pair.second, Spanned.SPAN_INCLUSIVE_INCLUSIVE); 
     Logger.d("SpoilerIndex:" + pair.toString()); 
    } 
    tvTestBlurText.setText(spanText); 
} 

private void getSpoilerIndex(String rawComment, int beginIndex, List<Pair<Integer, Integer>> spoilersContainer) { 
    int startIndex = rawComment.indexOf("[spoiler]", beginIndex); 
    int endIndex = rawComment.indexOf("[/spoiler]", beginIndex); 
    if (startIndex != -1 && endIndex != -1) { 
     spoilersContainer.add(new Pair<>(startIndex, endIndex + "[/spoiler]".length())); 
     getSpoilerIndex(rawComment, endIndex + "[/spoiler]".length(), spoilersContainer); 
    } 
} 

がMaskFilterSpanの間違った、または単にバグがありますか?

答えて

1

AndroidManifest.xmlでアクティビティにandroid:hardwareAccelerated="false"を設定すると、正しくレンダリングされます。

BlurMaskFilterはハードウェアアクセラレーションではサポートされていません。

現在サポートされていない描画操作を確認することができます迅速かつ正確な

http://developer.android.com/guide/topics/graphics/hardware-accel.html

+0

ワウを、! – floatingmuseum

関連する問題