Transition effects with Android ImageView

I have an ImageView, and when it is clicked, it should change the image using a transition (e.g. fade out, scroll, ...). 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 does not work with API <23 (Android 6.0).

+4
source share
1 answer

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 your 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 view the image where you want

check this also link

You need to create a new folder by right-clicking on the res folder, create a new folder name for it anim. And you can place xmls animation in it.

,

+3

Source: https://habr.com/ru/post/1672093/


All Articles