我有一些代码可以将图像动画留在屏幕上,然后我想让图像稍后在屏幕上显示动画。但是,当它在滚动到屏幕上之前重新开始动画时,它会在最后的位置闪烁,然后进入屏幕并进行动画制作。
xml喜欢这样:
animate on
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fillAfter="true">
<translate
android:fromXDelta="-50%p"
android:toXDelta="0%p"
android:duration="800" />
</set>
animate off
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fillAfter="true">
<translate
android:fromXDelta="0%p"
android:toXDelta="-50%p"
android:duration="800" />
</set>
java code
mEditMessage.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
if (mEditMessage.getText().length()==0){
Animation fade_in = AnimationUtils.loadAnimation(MessageActivity.this, R.anim.move_right_onto_screen);
AnimationSet animateIn = new AnimationSet(false);
animateIn.addAnimation(fade_in);
animateIn.setFillAfter(true);
mIvAttachment.startAnimation(animateIn);
mIvAudio.startAnimation(animateIn);
}
}
@Override
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
if (mEditMessage.getText().length()==0){
Animation fade_out = AnimationUtils.loadAnimation(MessageActivity.this, R.anim.move_left_off_screen);
AnimationSet animate = new AnimationSet(false);
animate.addAnimation(fade_out);
animate.setFillAfter(true);
mIvAttachment.startAnimation(animate);
mIvAudio.startAnimation(animate);
}
}
@Override
public void onTextChanged(CharSequence s, int start,
int before, int count) {
}
});