正如我在标题上提到的那样。有没有足够的方法来说明你想要动画的字符串的哪一部分? 我试图找出答案,希望大家都能给我一个建议来解决它?
我有点失落,我还没有探索过ObjectAnimator API,但我希望有人可以指导我使用ObjectAnimator和TextView来动画TextView中给定的单词。
例如:" Hello World Android",现在我希望淡出并淡出" World"。
示例代码:
public static void fadeEnhancedText(Context context,, TextView labEnchangedText) {
//animation add objectanimation
//MUST BE A WAY TO EXTRACT THE WORD
mAnimationSet.play(fadeIn(labEnchangedText)).after(fadeOut(labEnchangedText));
mAnimationSet.start();
}
private static ObjectAnimator fadeIn(TextView textView)
{
ObjectAnimator animation = ObjectAnimator.ofFloat(textView, "alpha",0f,1f);
animation.setDuration(500);
textView.setTextColor(Color.rgb(41, 41, 41));
return animation;
}
private static ObjectAnimator fadeOut(final TextView textView)
{
final int defaultColor = textView.getCurrentTextColor();
textView.setTextColor(Color.rgb(177, 24, 46));
ObjectAnimator animation = ObjectAnimator.ofFloat(textView, "alpha",1f,0f);
animation.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
textView.setTextColor(defaultColor);
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
animation.setRepeatCount(4);
animation.setDuration(1000);
return animation;
}