在
调用myImageView.clearAnimation()后找不到再次启动动画的解决方案。动画在 onPageSelected 中设置,但开始偏移量超时不起作用。
或者有没有其他方法可以取消 thr 动画以获得未触及的图像视图以及何时onPageSelected 被调用为同一视图再次启动相同的动画。
我试图在 onPageScrollStateChanged 中调用 myImageView.getAnimation().retart(),但动画仍在视图中...
这是我的代码:
public class myActivity extends Activity {
...
private ImageView myImageView;
private static final Integer startOffset = 5000;
private static final Integer duration= 2500;
@Override
public void onCreate(Bundle savedInstanceState) {
...
currentImageView = (ImageView) findViewById(R.id.dashboardIndicator);
currentImageView.setAnimation(indicatorAnimation());
...
}
private Animation indicatorAnimation() {
Animation alphaAnimation = new AlphaAnimation(1, 0.2F);
alphaAnimation.setInterpolator(new AccelerateInterpolator());
alphaAnimation.setStartOffset(startOffset);
alphaAnimation.setDuration(duration);
alphaAnimation.setFillAfter(true);
return alphaAnimation;
}
ViewPager.OnPageChangeListener onPageChangeListener = new ViewPager.OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
// Need here to start the animation again
myImageView.setAnimation(indicatorAnimation());
// Set's the animation but don't starts it after the startOffset timeout
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { }
@Override
public void onPageScrollStateChanged(int position) {
// Need here to cancel the animation to have no Alpha value on the imageview
myImageView.clearAnimation();
// image view 100% visible
}
};}
不需要
清除动画,直接调用starAnimation