android 如何向文本视图添加动画
How to add animation to a text view in android
我有一个 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"/>
下面是我如何在相应的 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);
您的 TextView
需要 setAnimation
示例:
tv.setAnimation( animation );
Android TextView 动画示例
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/
你的textview id 正确吗??首先检查您是否在您的应用程序中正确获取了您的 textview id
您可以在 Android 中从 AnimationUtils class 加载动画,并在 android 中将其设置为文本视图。
textview.startAnimation(AnimationUtils.loadAnimation(c, android.R.anim.fade_in));
你可以停止动画使用,
textview.clearAnimation();
使用Animator/AnimatorSet动画是遗留代码
我有一个 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"/>
下面是我如何在相应的 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);
您的 TextView
需要 setAnimation示例:
tv.setAnimation( animation );
Android TextView 动画示例
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/
你的textview id 正确吗??首先检查您是否在您的应用程序中正确获取了您的 textview id
您可以在 Android 中从 AnimationUtils class 加载动画,并在 android 中将其设置为文本视图。
textview.startAnimation(AnimationUtils.loadAnimation(c, android.R.anim.fade_in));
你可以停止动画使用,
textview.clearAnimation();
使用Animator/AnimatorSet动画是遗留代码