一種のスライドショーを作成しようとしています。このために、各アニメーションの最後に画像を変更してループをアニメーションにする必要があります。しかし、何らかの理由で、同じイベントがアニメーションごとに 2 回発生します。
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