TextView的文本大小而不是整个TextView的动画 [英] Animation of a TextView's text size and not the entire TextView

查看:250
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆