【发布时间】:2011-11-19 13:18:50
【问题描述】:
致各位
我有一个带有帧动画的动画图像,我从视图后面向上移动到屏幕上。当 TranslateAnimation 完成后,我想保持结束位置,因此 setFillAfter 设置为 true。
我的问题是当 TranslateAnimation 完成时帧动画停止了。如何重新启动或保持帧动画继续运行?
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
id="selected" android:oneshot="false">
<item android:drawable="@drawable/a" android:duration="200" />
<item android:drawable="@drawable/b" android:duration="200" />
<item android:drawable="@drawable/c" android:duration="200" />
</animation-list>
loadingView = (RelativeLayout) findViewById(R.id.loadingBar);
loadingView.setVisibility(View.VISIBLE);
loadingImage = (ImageView) loadingView.findViewById(R.id.loading);
loadingImage.setBackgroundResource(R.drawable.loading);
animateImages = (AnimationDrawable) loadingImage.getBackground();
translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF,0.0f, Animation.RELATIVE_TO_SELF, -1.0f);
translateAnimation.setInterpolator(new AccelerateInterpolator());
translateAnimation.setDuration(2000);
translateAnimation.setFillEnabled(true);
translateAnimation.setFillAfter(true);
translateAnimation.setAnimationListener(new AnimationListener()
{
@Override
public void onAnimationStart(Animation animation)
{
// TODO Auto-generated method stub
animateImages.start();
}
@Override
public void onAnimationEnd(Animation arg0)
{
}
@Override
public void onAnimationRepeat(Animation animation)
{
// TODO Auto-generated method stub
}
});
loadingView.startAnimation(translateAnimation);
【问题讨论】:
-
你能显示你的帧动画xml吗?
-
用帧动画xml更新了问题。
-
我在触摸屏幕时唯一注意到的另一件事是,只要我触摸屏幕,动画就会开始。当我把手拿开时它就停止了。
标签: android animation translation frame