Example:- Implement Basic Android Animations ?
fade_in_anim.xml
...................................................................................................................................................................
xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<alpha
android:duration="4000"
android:fromAlpha="0.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:toAlpha="1.0" />
</set>
...................................................................................................................................................................
fade_out.xml
...................................................................................................................................................................
xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<alpha
android:duration="1000"
android:fromAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:toAlpha="0.0" />
</set>
...................................................................................................................................................................
blink_anim.xml
...................................................................................................................................................................
xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="600"
android:repeatMode="reverse"
android:repeatCount="infinite"/>
</set>
...................................................................................................................................................................
zoom_anim.xml
...................................................................................................................................................................
xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="3"
android:toYScale="3" >
</scale>
</set>
...................................................................................................................................................................
zoom_out_anim.xml
...................................................................................................................................................................
xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="3"
android:toYScale="3" >
</scale>
</set>
...................................................................................................................................................................
rotate_anim.xml
...................................................................................................................................................................
xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="600"
android:repeatMode="restart"
android:repeatCount="infinite"
android:interpolator="@android:anim/cycle_interpolator"/>
</set>
...................................................................................................................................................................
move_anim.xml
...................................................................................................................................................................
xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fillAfter="true">
<translate
android:fromXDelta="0%p"
android:toXDelta="75%p"
android:duration="800" />
</set>
...................................................................................................................................................................
slid_up_anim.xml
...................................................................................................................................................................
xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<scale
android:duration="500"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:interpolator="@android:anim/linear_interpolator"
android:toXScale="1.0"
android:toYScale="0.0" />
</set>
...................................................................................................................................................................
slid_down.xml
...................................................................................................................................................................
xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<scale
android:duration="500"
android:fromXScale="1.0"
android:fromYScale="0.0"
android:toXScale="1.0"
android:toYScale="1.0" />
</set>
...................................................................................................................................................................
bounce_anim.xml
...................................................................................................................................................................
xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:interpolator="@android:anim/bounce_interpolator">
<scale
android:duration="500"
android:fromXScale="1.0"
android:fromYScale="0.0"
android:toXScale="1.0"
android:toYScale="1.0" />
</set>
...................................................................................................................................................................
sequential_anim.xml
...................................................................................................................................................................
xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:interpolator="@android:anim/linear_interpolator"
>
<translate
android:duration="800"
android:fillAfter="true"
android:fromXDelta="0%p"
android:startOffset="300"
android:toXDelta="75%p" />
<translate
android:duration="800"
android:fillAfter="true"
android:fromYDelta="0%p"
android:startOffset="1100"
android:toYDelta="70%p" />
<translate
android:duration="800"
android:fillAfter="true"
android:fromXDelta="0%p"
android:startOffset="1900"
android:toXDelta="-75%p" />
<translate
android:duration="800"
android:fillAfter="true"
android:fromYDelta="0%p"
android:startOffset="2700"
android:toYDelta="-70%p" />
<rotate
android:duration="1000"
android:fromDegrees="0"
android:interpolator="@android:anim/cycle_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="3800"
android:repeatCount="infinite"
android:repeatMode="restart"
android:toDegrees="360" />
</set>
...................................................................................................................................................................
together_anim.xml
...................................................................................................................................................................
xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:interpolator="@android:anim/linear_interpolator"
>
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="4000"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="4"
android:toYScale="4" >
</scale>
<rotate
android:duration="500"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:repeatMode="restart"
android:toDegrees="360" />
</set>
...................................................................................................................................................................
activity_main.xml
...................................................................................................................................................................
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
//fade In.................1
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_margin="3dp"
android:orientation="horizontal">
<Button
android:text="Fade_In"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="@+id/Btn_fade_in"
android:layout_marginRight="40dp"
/>
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
app:srcCompat="@drawable/log_icon"
android:id="@+id/img_fade_in"
android:layout_weight="1"
/>
</LinearLayout>
//fade Out.................2
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_margin="3dp"
android:orientation="horizontal">
<Button
android:text="Fade_Out"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="@+id/Btn_fade_out"
android:layout_marginRight="40dp"
/>
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
app:srcCompat="@drawable/log_icon"
android:id="@+id/img_fade_out"
android:layout_weight="1"
/>
</LinearLayout>
//Blink.................3
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_margin="3dp"
android:orientation="horizontal">
<Button
android:text="Blink"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="@+id/Btn_blink"
android:layout_marginRight="40dp"
/>
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
app:srcCompat="@drawable/log_icon"
android:id="@+id/img_blink"
android:layout_weight="1"
/>
</LinearLayout>
//Zoom.................4
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_margin="3dp"
android:orientation="horizontal">
<Button
android:text="Zoom"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="@+id/Btn_zoom"
android:layout_marginRight="40dp"
/>
<ImageView
android:layout_width="80dp"
android:layout_height="wrap_content"
app:srcCompat="@drawable/log_icon"
android:id="@+id/img_zoom"
android:layout_weight="1"
/>
</LinearLayout>
//Zoom_out................5
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_margin="3dp"
android:orientation="horizontal">
<Button
android:text="Zoom
Out"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="@+id/Btn_zoom_out"
android:layout_marginRight="40dp"
/>
<ImageView
android:layout_width="80dp"
android:layout_height="wrap_content"
app:srcCompat="@drawable/log_icon"
android:id="@+id/img_zoom_out"
android:layout_weight="1" />
</LinearLayout>
//Rotate.................6
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_margin="3dp"
android:orientation="horizontal">
<Button
android:text="Rotate"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="@+id/Btn_rotate"
android:layout_marginRight="40dp"
/>
<ImageView
android:layout_width="80dp"
android:layout_height="wrap_content"
app:srcCompat="@drawable/log_icon"
android:id="@+id/img_rotate"
android:layout_weight="1"
/>
</LinearLayout>
//Move.................7
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_margin="3dp"
android:orientation="horizontal">
<Button
android:text="Move"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="@+id/Btn_move"
android:layout_marginRight="40dp"
/>
<ImageView
android:layout_width="80dp"
android:layout_height="wrap_content"
app:srcCompat="@drawable/log_icon"
android:id="@+id/img_move"
android:layout_weight="1"
/>
</LinearLayout>
//Slid_up.................7
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_margin="3dp"
android:orientation="horizontal">
<Button
android:text="Slid
Up"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="@+id/Btn_slid_up"
android:layout_marginRight="40dp"
/>
<ImageView
android:layout_width="80dp"
android:layout_height="wrap_content"
app:srcCompat="@drawable/log_icon"
android:id="@+id/img_slid_up"
android:layout_weight="1"
/>
</LinearLayout>
//Slid_down.................8
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_margin="3dp"
android:orientation="horizontal">
<Button
android:text="Slid
Down"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="@+id/Btn_slid_down"
android:layout_marginRight="40dp"
/>
<ImageView
android:layout_width="80dp"
android:layout_height="wrap_content"
app:srcCompat="@drawable/log_icon"
android:id="@+id/img_slid_down"
android:layout_weight="1"
/>
</LinearLayout>
//Bounce.................9
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_margin="3dp"
android:orientation="horizontal">
<Button
android:text="Bounce"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="@+id/Btn_bounce"
android:layout_marginRight="40dp"
/>
<ImageView
android:layout_width="80dp"
android:layout_height="wrap_content"
app:srcCompat="@drawable/log_icon"
android:id="@+id/img_bounce"
android:layout_weight="1" />
</LinearLayout>
//Sequential.................10
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_margin="3dp"
android:orientation="horizontal">
<Button
android:text="Sequential"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="@+id/Btn_Sequential"
android:layout_marginRight="40dp"
/>
<ImageView
android:layout_width="80dp"
android:layout_height="wrap_content"
app:srcCompat="@drawable/log_icon"
android:id="@+id/img_Sequential"
android:layout_weight="1"
/>
</LinearLayout>
//Together.................11
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_margin="3dp"
android:orientation="horizontal">
<Button
android:text="Together"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="@+id/Btn_Together"
android:layout_marginRight="40dp"
/>
<ImageView
android:layout_width="80dp"
android:layout_height="wrap_content"
app:srcCompat="@drawable/log_icon"
android:id="@+id/img_Together"
android:layout_weight="1"
/>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
...................................................................................................................................................................
MainActivity.java
...................................................................................................................................................................
import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
Button Btn_fade_in,Btn_fade_out,Btn_blink,Btn_zoom,Btn_zoom_out,Btn_rotate,Btn_move,Btn_slid_up,Btn_slid_down,Btn_bounce,Btn_Sequential,Btn_Together;
ImageView img_fade_in,img_fade_out,img_blink,img_zoom,img_zoom_out,img_rotate,img_move,img_slid_up,img_slid_down,img_bounce,img_Sequential,img_Together;
Animation animFadeIn,animFadeout,animblink,animzoom,animzoomout,animrotate,animmove,animslidup,animsliddown,animbounce,animSequential,animTogether;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Btn_fade_in=(Button)findViewById(R.id.Btn_fade_in);
Btn_fade_in.setOnClickListener(this);
img_fade_in=(ImageView)findViewById(R.id.img_fade_in);
Btn_fade_out=(Button)findViewById(R.id.Btn_fade_out);
Btn_fade_out.setOnClickListener(this);
img_fade_out=(ImageView)findViewById(R.id.img_fade_out);
Btn_blink=(Button)findViewById(R.id.Btn_blink);
Btn_blink.setOnClickListener(this);
img_blink=(ImageView)findViewById(R.id.img_blink);
Btn_zoom=(Button)findViewById(R.id.Btn_zoom);
Btn_zoom.setOnClickListener(this);
img_zoom=(ImageView)findViewById(R.id.img_zoom);
Btn_zoom_out=(Button)findViewById(R.id.Btn_zoom_out);
Btn_zoom_out.setOnClickListener(this);
img_zoom_out=(ImageView)findViewById(R.id.img_zoom_out);
Btn_rotate=(Button)findViewById(R.id.Btn_rotate);
Btn_rotate.setOnClickListener(this);
img_rotate=(ImageView)findViewById(R.id.img_rotate);
Btn_move=(Button)findViewById(R.id.Btn_move);
Btn_move.setOnClickListener(this);
img_move=(ImageView)findViewById(R.id.img_move);
Btn_slid_up=(Button)findViewById(R.id.Btn_slid_up);
Btn_slid_up.setOnClickListener(this);
img_slid_up=(ImageView)findViewById(R.id.img_slid_up);
Btn_slid_down=(Button)findViewById(R.id.Btn_slid_down);
Btn_slid_down.setOnClickListener(this);
img_slid_down=(ImageView)findViewById(R.id.img_slid_down);
Btn_bounce=(Button)findViewById(R.id.Btn_bounce);
Btn_bounce.setOnClickListener(this);
img_bounce=(ImageView)findViewById(R.id.img_bounce);
Btn_Sequential=(Button)findViewById(R.id.Btn_Sequential);
Btn_Sequential.setOnClickListener(this);
img_Sequential=(ImageView)findViewById(R.id.img_Sequential);
Btn_Together=(Button)findViewById(R.id.Btn_Together);
Btn_Together.setOnClickListener(this);
img_Together=(ImageView)findViewById(R.id.img_Together);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.Btn_fade_in:
animFadeIn = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade_in_anim);
img_fade_in.startAnimation(animFadeIn);
break;
case R.id.Btn_fade_out:
animFadeout = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade_out);
img_fade_out.startAnimation(animFadeout);
break;
case R.id.Btn_blink:
animblink = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.blink_anim);
img_blink.startAnimation(animblink);
break;
case R.id.Btn_zoom:
animzoom = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.zoom_anim);
img_zoom.startAnimation(animzoom);
break;
case R.id.Btn_zoom_out:
animzoomout = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.zoom_out_anim);
img_zoom_out.startAnimation(animzoomout);
break;
case R.id.Btn_rotate:
animrotate = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotate_anim);
img_rotate.startAnimation(animrotate);
break;
case R.id.Btn_move:
animmove = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.move_anim);
img_move.startAnimation(animmove);
break;
case R.id.Btn_slid_up:
animslidup = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slid_up_anim);
img_slid_up.startAnimation(animslidup);
break;
case R.id.Btn_slid_down:
animsliddown = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slid_down);
img_slid_down.startAnimation(animsliddown);
break;
case R.id.Btn_bounce:
animbounce = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.bounce_anim);
img_bounce.startAnimation(animbounce);
break;
case R.id.Btn_Sequential:
animSequential = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.sequential_anim);
img_Sequential.startAnimation(animSequential);
break;
case R.id.Btn_Together:
animTogether = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.together_anim);
img_Together.startAnimation(animTogether);
break;
}
}
}
...................................................................................................................................................................
try this anim