如何在Android的文本视图中添加动画 [英] How to add animation to a text view in android

查看:129
本文介绍了如何在Android的文本视图中添加动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 TextView ,我正在尝试向其中添加淡入淡出的动画。我的代码返回 null ,我不明白为什么。

I have a TextView and I'm trying to add a fade in animation to it. My code is returning null and I don't understand why.

这是我的实现

这是 fade_in.xml

    <alpha
            xmlns:android="http://schemas.android.com/apk/res/android"    android:fillAfter="true"
            android:duration="1000"
            android:fromAlpha="0.0"
            android:interpolator="@android:anim/accelerate_interpolator"
            android:toAlpha="1.0"/>

这是即时通讯在相应活动中的使用方式

and here is how im using it in the corresponding activity

    tv= (TextView)findViewById(R.id.textView);
//-- the below line is returning null
            animation = AnimationUtils.loadAnimation(this,R.anim.fade_in);

            animation.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {
                tv.setVisibility(View.VISIBLE);
                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    Intent it  = new Intent(SplashActivity.this, MainActivity.class);
                    startActivity(it);
                }

                @Override
                public void onAnimationRepeat(Animation animation) {

                }
            });

            tv.startAnimation(animation);


推荐答案

Android TextView Annimation示例

Android TextView Annimation example

XML

<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
      android:fromXScale="1.0"
      android:fromYScale="1.0"
      android:toXScale="2.0"
      android:toYScale="2.0"
      android:duration="3000"></scale>
</set>

代码

private void RunAnimation() 
{
  Animation a = AnimationUtils.loadAnimation(this, R.anim.scale);
  a.reset();
  TextView tv = (TextView) findViewById(R.id.firstTextView);
  tv.clearAnimation();
  tv.startAnimation(a);
}

更多:

http://chiuki.github.io/advanced-android-textview/# / 5

http://www.hascode.com/2010/09/playing-around-with-the-android-animation-framework/

这篇关于如何在Android的文本视图中添加动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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