【发布时间】:2012-05-03 20:51:17
【问题描述】:
在我调用 myImageView.clearAnimation() 后找不到重新启动动画的解决方案。动画在 onPageSelected 中设置,但 startoffset 超时不起作用。
或者是否有任何其他方法可以取消 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
}
};}
【问题讨论】:
标签: android android-animation android-viewpager