I have created the following method to animate multiple images in a single ImageView
. My problem is that the image transitions are abrupt, so what I would now like to do is make it so that the images fade from one to the next.
So how could I achieve that (without creating additional images)?
protected static void setAnimatedImagesForImageView(Context context, ImageView imageView, Uri[] imageUris, int durationMillis) {
AnimationDrawable animation = new AnimationDrawable();
boolean imageAdded = false;
Drawable drawable;
for (int i = 0; i < imageUris.length; i++) {
if (imageUris[i] != null) {
drawable = getDrawable(context, imageUris[i]);
if (drawable != null) {
animation.addFrame(drawable, durationMillis);
imageAdded = true;
}
}
}
if (imageAdded) {
animation.setOneShot(false);
imageView.setImageDrawable(animation);
animation.start();
}
}
public static Drawable getDrawable(Context context, Uri drawableUri) {
if (drawableUri == null) {
return null;
}
else {
try {
InputStream inputStream = context.getContentResolver().openInputStream(drawableUri);
return Drawable.createFromStream(inputStream, drawableUri.toString());
} catch (Exception e) {
Log.e(LOG_TAG, "Could not get Drawable for Uri", e);
return null;
}
}
}