gpt4 book ai didi

Android:清除动画后如何重新启动动画

转载 作者:行者123 更新时间:2023-11-29 13:59:09 24 4
gpt4 key购买 nike

在我调用 myImageView.clearAnimation() 后找不到再次启动动画的解决方案。动画在 onPageSelected 中设置,但 startoffset 超时不起作用。

或者是否有任何其他方法可以取消动画以获得未触及的 imageview 以及何时onPageSelected 被调用为相同的 View 启动相同的动画。

我尝试在 onPageScrollStateChanged 中调用 myImageView.getAnimation().retart() 但动画仍在 View 中...

这是我的代码:

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

关于Android:清除动画后如何重新启动动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10431568/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com