2015-02-01 1 views
0

spannablestringbuilder를 애니메이션으로 변환하려고했습니다. 그러나 장치 Logcat : "PropertyValuesHolder : 대상 클래스 클래스에서 float 유형의 메소드 setAlpha()"로부터이 메시지가 나타납니다.ObjectAnimator를 사용하여 SpannableStringBuilder 애니메이션을 적용 할 수 없습니다.

순수한 문자열에 애니메이션을 적용하는 방법에 대한 아이디어는 무엇입니까?

내가 무엇을 해왔의 코드 : 유형 getSpans 호출 (당신이 텍스트 뷰와 같은 유형을 지정)하는 setAlpha 방법이없는에서 스팬에 대해 반환

private static void fadeEnhancedText(Context context,TextView labText, TextView labEnchangedText, 
             int defaultColor) { 
     //animation add objectanimation 
     SpannableStringBuilder mSpannableStringBuilder= 
       new SpannableStringBuilder(labEnchangedText 
         .getText().toString()); 
     mSpannableStringBuilder.setSpan(mForegroundColorSpan, mMatcher.start(), 
       mMatcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 
     labText.setText(labEnchangedText.getText().toString()); 
     labText.setVisibility(View.GONE); 
     //TODO spannable problem fader doesn't work fully 
     labEnchangedText.setText(mSpannableStringBuilder, TextView.BufferType.SPANNABLE); 
     mAnimationSet.play(fadeIn(labEnchangedText,mSpannableStringBuilder)). 
       after(fadeOut(labEnchangedText, 
       labText, 
       defaultColor,mSpannableStringBuilder)); 
     mAnimationSet.start(); 
    } 

    private static ObjectAnimator fadeIn(TextView textView, SpannableStringBuilder spannableStringBuilder) 
    { 
     ObjectAnimator animation = ObjectAnimator.ofFloat(spannableStringBuilder.getSpans(mMatcher.start(), 
       mMatcher.end(),textView.getClass()), "alpha",0f,1f); 
     animation.setDuration(300); 
     return animation; 

    } 

    private static ObjectAnimator fadeOut(final TextView textView, final TextView currentView, final int defaultColor, 
              final SpannableStringBuilder spannableStringBuilder) 
    { 
     //textView.setTextColor(Color.rgb(177, 24, 46)); 
     ObjectAnimator animation = ObjectAnimator.ofFloat(spannableStringBuilder.getSpans(mMatcher.start(), 
       mMatcher.end(),textView.getClass()), "alpha",1f,0f); 
     animation.addListener(new Animator.AnimatorListener() { 
      @Override 
      public void onAnimationStart(Animator animation) { 

      } 

      @Override 
      public void onAnimationEnd(Animator animation) { 
       textView.setTextColor(defaultColor); 
       currentView.setVisibility(View.VISIBLE); 
      } 

      @Override 
      public void onAnimationCancel(Animator animation) { 

      } 

      @Override 
      public void onAnimationRepeat(Animator animation) { 

      } 
     }); 
     animation.setRepeatCount(4); 
     animation.setDuration(300); 
     return animation; 

    } 

답변

1

텍스트 뷰를 (도 아니고 getAlpha 메소드). 또한 ObjectAnimator가 어떻게 배열을 좋아하는지 모르겠다. 그러나 나는 그것을 시도하지 않았다.

TextView 투명성을 위해 Android Transparent TextView?을 살펴보십시오. How to display HTML in TextView? 또는 문자열 리소스 가이드 참조 : http://developer.android.com/guide/topics/resources/string-resource.html#StylingWithHTML

또한 텍스트의 스타일을 HTML을 사용할 수있을

관련 문제