如何在android中的文本视图中添加动画

Dee*_*dav 18 animation android fadein

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

这是我的实施

这是 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"/>
Run Code Online (Sandbox Code Playgroud)

以下是如何在相应的活动中使用它

    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);
Run Code Online (Sandbox Code Playgroud)

RAP*_*RAP 16

Android TextView Annimation示例

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>
Run Code Online (Sandbox Code Playgroud)

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);
}
Run Code Online (Sandbox Code Playgroud)

更多:

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

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