Reputation: 614
I have an ImageView, and when it is clicked it has to change image using a transition (e.g. fading, scrolling, ...). How can I do this?
I tried this code
imageView.animate().alpha(0f).setDuration(2000);
imageView.setImageResource(R.drawable.icon_wb);
imageView.animate().alpha(1f).setDuration(2000);
but it doesn't work with an API < 23 (Android 6.0).
Upvotes: 4
Views: 10398
Reputation: 912
fadeout.xml
<alpha
android:duration="4000"
android:fromAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:toAlpha="0.0" />
fadein.xml
<alpha
android:duration="6000"
android:fromAlpha="0.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:toAlpha="1.0" />
In you java class
Animation animFadeOut = AnimationUtils.loadAnimation(this, R.anim.fade_out);
Animation animFadeIn = AnimationUtils.loadAnimation(this, R.anim.fade_in);
animFadeOut.reset();
imageview.clearAnimation();
imageview.startAnimation(animFadeOut);
animFadeIn.reset();
imageview.clearAnimation();
imageview.startAnimation(animFadeIn);
and hide or visible imageview where u want
check this also link
You need to create a new folder right click on res folder create new folder name it anim. And you can put your animation xmls in it.
Also check this tutorial site its give step by step tutorial link
Upvotes: 5