Animate Imageview From Alpha 0 To 1
I have an imageView that I want to start as invisible. After a certain button is clicked, I want to animate the Image into view and then I want it to remain at alpha 1. How do I do
Solution 1:
Try to make your ImageView invisible
in xml:
<ImageView...android:visibility="invisible"/>
Then, by adding an AnimationListener
, make it visible
in onAnimationStart
:
...
animation1.setFillAfter(true);
animation1.setAnimationListener(newAnimationListener() {
@OverridepublicvoidonAnimationStart(Animation animation) {
// pass it visible before starting the animation
tokenBtn.setVisibility(View.VISIBLE);
}
@OverridepublicvoidonAnimationRepeat(Animation animation) { }
@OverridepublicvoidonAnimationEnd(Animation animation) { }
});
// finally, start the animation
tokenBtn.startAnimation(animation1);
Solution 2:
In MainActivity.java add
publicvoidblink(View view) {
ImageViewimage= (ImageView) findViewById(R.id.imageView);
Animationanimation= AnimationUtils.loadAnimation(getApplicationContext(), R.anim.blink);
image.startAnimation(animation1);
}
Create file named blink.xml in res>anim folder and add this code
<?xml version="1.0" encoding="utf-8"?><setxmlns:android="http://schemas.android.com/apk/res/android"><alphaandroid:fromAlpha="0.0"android:toAlpha="1.0"android:interpolator="@android:anim/accelerate_interpolator"android:duration="--YOUR DURATION--"android:repeatMode="reverse"android:repeatCount="0"/></set>
And make sure that onClick function on button is named blink
Solution 3:
You can simply set initial alpha to 0 then animate it through 1 with desired duration;
imageView.setAlpha(0);
imageView.animate()
.alpha(1)
.setDuration(200);
Post a Comment for "Animate Imageview From Alpha 0 To 1"