Как добавить анимацию в текстовое представление в 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"/>
и вот как im использует его в соответствующей деятельности
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);
Ответы
Ответ 1
Пример аннотации 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/
Ответ 2
Правильно ли указан ваш текст? Сначала проверьте, правильно ли вы получаете свой текстовый код в своем приложении.
Ответ 3
Вы можете загружать анимации из класса AnimationUtils в Android и устанавливать его в текстовое окно в Android.
textview.startAnimation(AnimationUtils.loadAnimation(c, android.R.anim.fade_in));
и вы можете остановить анимацию, используя
textview.clearAnimation();
Ответ 4
Вам нужно setAnimation в вашем TextView
Пример:
tv.setAnimation( animation );
Ответ 5
Использование Animator/AnimatorSet Анимация - это устаревший код