Я пытаюсь добавить анимацию Fade in & Fade out для изображений в приложении, у меня это получается успешно, но я могу видеть пробел / фон во время перехода изображения.
Пожалуйста дайте мне знать, как убрать белый фон с переходом изображения.
fade_in_animation. xml
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:duration="2000"
android:fromAlpha="0.0"
android:toAlpha="1.0"/>
</set>
fade_out_animation. xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:duration="2000"
android:fromAlpha="1.0"
android:toAlpha="0.0"/>
</set>
Ниже приведен мой java код.
private void initBannerImages(List<String> mBannerImages, final List<String> mImageDesc) {
final Animation animationFadeIn = AnimationUtils.loadAnimation(mContext, R.anim.fade_in_animation);
final Animation animationFadeOut = AnimationUtils.loadAnimation(mContext, R.anim.fade_out_animation);
Animation.AnimationListener animListener = new Animation.AnimationListener() {
// Required to change the image
int count = 1;
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
if (animation == animationFadeIn) {
// Start fade-out animation
mTimetotravelBinding.imgTravelBannerImage.startAnimation(animationFadeOut);
mTimetotravelBinding.txtImageDescription.startAnimation(animationFadeOut);
} else if (animation == animationFadeOut) {
count++;
mTimetotravelBinding.txtImageDescription.setText(mImageDesc.get(count - 1));
Glide.with(mContext).load(mBannerImages.get(count - 1)).dontAnimate().into(mTimetotravelBinding.imgTravelBannerImage);
mTimetotravelBinding.imgTravelBannerImage.startAnimation(animationFadeIn);
mTimetotravelBinding.txtImageDescription.startAnimation(animationFadeIn);
if (count == mImageDesc.size()) {
count = 0;
}
}
}
};
// Set listener to animation
animationFadeIn.setAnimationListener(animListener);
animationFadeOut.setAnimationListener(animListener);
// Start fade-in animation
mTimetotravelBinding.txtImageDescription.setText(mImageDesc.get(0));
Glide.with(mContext).load(mBannerImages.get(0)).into(mTimetotravelBinding.imgTravelBannerImage);
mTimetotravelBinding.txtImageDescription.startAnimation(animationFadeIn);
mTimetotravelBinding.imgTravelBannerImage.startAnimation(animationFadeIn);
}
Также ниже приведен скриншот для справки.