TextView 的文本大小而不是整个 TextView 的动画 [英] Animation of a TextView's text size and not the entire TextView
本文介绍了TextView 的文本大小而不是整个 TextView 的动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法只为 TextView 的文本大小设置动画而不缩放整个 TextView 的布局?
Is there a way to animate only the TextView's text size without scaling the entire TextView's layout?
我正在尝试实现类似的效果,请注意文本会重新调整为单行,而其大小会变小.
Am trying to achieve a similar effect, Note the text re-sizes to a single line while its size becomes smaller.
推荐答案
这可以通过 ValueAnimator
来实现,我认为它应该看起来像这样:
This could be achieved with a ValueAnimator
and from the top of my head I think it should look something like this:
final TextView tv = new TextView(getApplicationContext());
final float startSize = 42; // Size in pixels
final float endSize = 12;
long animationDuration = 600; // Animation duration in ms
ValueAnimator animator = ValueAnimator.ofFloat(startSize, endSize);
animator.setDuration(animationDuration);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
float animatedValue = (float) valueAnimator.getAnimatedValue();
tv.setTextSize(animatedValue);
}
});
animator.start();
这篇关于TextView 的文本大小而不是整个 TextView 的动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文