Animation

1) Fade

1) To make an image fade out, access the animate method from the View object

2) Any local variable in a method that needs to accessed by inner classes (Runnable in this case) must be final. If you dont want to declare final, make the variable global

3) If you fade out a widget,set visibility to GONE, otherwise, the widget will be clickable and interfere

//any local variable in a method that needs to accessed by inner classes must be final.
    // if you dont want to declare final, make the variable global
    final ImageView img1 = (ImageView) findViewById(R.id.imageView2);

    // 2000ms = 2 seconds
    img1.animate().alpha(0f).setDuration(2000).withEndAction(new Runnable() {
                @Override
                public void run() {
                    //part of the code that will be executed after animation ends
                    img1.setVisibility(View.GONE);
                }
            });

NOTE (Image scale) : To set image to fill the screen, set scale to fitXY

2) Translation, Rotation

img.animate().translateXBy(-10f).setDuration(2000); // move left by 10 pixels    
    img.animate().translateXBy(10f).setDuration(2000); // move right by 10 pixels
    img.animate().translateYBy(10f).setDuration(2000); // move up by 10 pixels
    img.animate().translateYBy(-10f).setDuration(2000); // move down by 10 pixels

    img.animate().rotation(180f).setDuration(2000); // rotate by 180 degree clockwise
    img.animate().rotation(180f*10f).setDuration(2000); // rotate by 10 times clockwise in 2s
    img.animate().rotation(-180f).setDuration(2000); // rotate by 180 degree anti-clockwise

3) Scaling (Shrink and expand)

img.animate().scaleX(0.5f).scaleY(0.3f).setDuration(2000) //set the new desired length and breadth

Combining animations

public class MainActivity extends AppCompatActivity {

        public void animateFunction(View view){
            ImageView bart = (ImageView) findViewById(R.id.imageView);

            //spins to position from out of screen
            bart.animate().translationXBy(1000f).translationYBy(1000f).rotation(3600f).setDuration(2000);

            //traslate with respect to absolute coords
            //bart.animate().translationX(180f).translationY(140f).rotation(3600f).setDuration(2000);

            //feels like widget is moving in z axis
            //bart.animate().scaleX(0.5f).scaleY(0.5f).translationXBy(200f).translationYBy(300f).setDuration(2000);
        }
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            ImageView bart = (ImageView) findViewById(R.id.imageView);

            //set the image initially out of screen
            bart.setTranslationX(-1000f);
            bart.setTranslationY(-1000f);

        }
    }