TransitionDrawable animation
suggest changeThis example displays a transition for an image view with only two images. More images can be used as well, one after the other, for the first and second layer positions after each transition, as a loop.
- Add an image array to
res/values/arrays.xml
<resources>
<array
name="splash_images">
<item>@drawable/splash_image_first</item>
<item>@drawable/splash_image_second</item>
</array>
</resources>
private Drawable[] backgroundsDrawableArrayForTransition;
private TransitionDrawable transitionDrawable;
private void backgroundAnimTransAction() {
// set res image array
Resources resources = getResources();
TypedArray icons = resources.obtainTypedArray(R.array.splash_images);
@SuppressWarnings("ResourceType")
Drawable drawable = icons.getDrawable(0); // starting image
@SuppressWarnings("ResourceType")
Drawable drawableTwo = icons.getDrawable(1); // ending image
icons.recycle();
backgroundsDrawableArrayForTransition = new Drawable[2];
backgroundsDrawableArrayForTransition[0] = drawable;
backgroundsDrawableArrayForTransition[1] = drawableTwo;
transitionDrawable = new TransitionDrawable(backgroundsDrawableArrayForTransition);
// your image view here - backgroundImageView
backgroundImageView.setImageDrawable(transitionDrawable);
transitionDrawable.startTransition(4000);
transitionDrawable.setCrossFadeEnabled(false); // call public methods
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents