Saturday, April 30, 2016

Android - animation in Image View

The goal was to create an animation effect of fading one image and then other appear. Below code and settings could do this.

ImageView view = (ImageView) findViewById(R.id.slide_show_image_view);
    if (view != null) {
        Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade);
        view.startAnimation(animation);
        imgView.setImageBitmap(bitmapCache);

    }

This required the anim file like this below 
  
    "1.0" encoding="utf-8"?
    "http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
    
   
android:fromAlpha="0"
android:toAlpha="1"
android:duration="2000"
   
    
   
android:startOffset="8000"
android:fromAlpha="1"
android:toAlpha="0"
android:duration="2000"
   
    
    

It is important to keep the animation durations right so that it gives good efect. 

references:

No comments:

Post a Comment