gpt4 book ai didi

android - Android 上的双启动 onAnimationEnd

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:27:28 25 4
gpt4 key购买 nike

我正在尝试创建一种幻灯片放映。为此,我需要在每个动画结束时通过图像的变化来制作循环动画。但无论出于何种原因,同一事件在每个动画中发生两次

public cPhotoSlide(Activity _activity, DBHelper _helper, int idMenu, cItemViewer _ItemViewer){
activity = _activity;
helper = _helper;
ImageManager = helper.ImageManager;
ItemViewer = _ItemViewer;
cursor = 0;
itemIds = ChildsItemsToTable(idMenu);
MainLayout = (RelativeLayout) activity.findViewById(R.id.fon);
SliderObj = activity.getLayoutInflater().inflate(R.layout.photo_slide, MainLayout, true);
SlideImage = (ImageView) SliderObj.findViewById(R.id.slide_image);
SlideImage.setImageBitmap(ImageManager.loadImage(activity.getApplicationContext(),itemIds.get(cursor)));

animationSlide = (AnimationSet) AnimationUtils.loadAnimation(activity.getApplicationContext(), R.anim.slide);

animationSlide.getAnimations().get(1).setAnimationListener(
new AnimationListener() {
public void onAnimationStart(Animation animation) {}
public void onAnimationRepeat(Animation animation) {}
public void onAnimationEnd(Animation animation) {
Log.d(LOG_TAG,"Cursor = "+cursor+"/"+itemIds.size());
if (cursor >= itemIds.size()-1) {
cursor = 0;
} else {
cursor += 1;
}
if (itemIds.get(cursor).content != 0) {
SlideImage.setImageBitmap(ImageManager.loadImage(itemIds.get(cursor)));
}
SlideImage.startAnimation(animationSlide);
}
}
);

SlideImage.startAnimation(animationSlide);
}

在 XML 中:

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator">
<alpha
android:duration="250"
android:fromAlpha="0.0"
android:toAlpha="1.0">
</alpha>
<alpha
android:startOffset="2000"
android:duration="250"
android:fromAlpha="1.0"
android:toAlpha="0.0">
</alpha>
</set>

在日志中:

01-30 15:52:26.700: D/cPhotoSlide(22301): Cursor = 0/207
01-30 15:52:26.716: D/cPhotoSlide(22301): Cursor = 1/207
01-30 15:52:28.990: D/cPhotoSlide(22301): Cursor = 2/207
01-30 15:52:29.005: D/cPhotoSlide(22301): Cursor = 3/207
01-30 15:52:31.279: D/cPhotoSlide(22301): Cursor = 4/207
01-30 15:52:31.302: D/cPhotoSlide(22301): Cursor = 5/207
01-30 15:52:33.575: D/cPhotoSlide(22301): Cursor = 6/207
01-30 15:52:33.591: D/cPhotoSlide(22301): Cursor = 7/207
01-30 15:52:35.865: D/cPhotoSlide(22301): Cursor = 8/207
01-30 15:52:35.888: D/cPhotoSlide(22301): Cursor = 9/207
01-30 15:52:38.161: D/cPhotoSlide(22301): Cursor = 10/207
01-30 15:52:38.177: D/cPhotoSlide(22301): Cursor = 11/207

最佳答案

您的动画集由两个动画组成,并且您的代码被每个动画调用,要解决此问题,您可以这样做:

animationSlide.getAnimations().get(1).setAnimationListener(.....);

代替

animationSlide.setAnimationListener(.....);

关于android - Android 上的双启动 onAnimationEnd,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14603441/

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