Animate an ImageView in Android

by Sasikumar 2014-03-07 14:29:20

layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
android:layout_marginTop="80dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:gravity="center"
android:textColor="#000099"
android:textSize="30dp"
android:text="Demo - Animate an ImageView" />

<ImageView
android:layout_gravity="center_horizontal"
android:layout_marginTop="120dp"
android:id="@+id/myImageView"
android:layout_width="200dp"
android:layout_height="200dp"
android:src="@drawable/clock" />

</LinearLayout>

MainActivity .java
public class MainActivity extends Activity
{

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

ImageView image=(ImageView)findViewById(R.id.myImageView);

// Create the RotateAnimation object
RotateAnimation anim = new RotateAnimation(0f, 350f, 15f, 15f);
// Set the Animation properties
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(700);

// Start animating the image
image.startAnimation(anim);

// To Stop the animation
// image.setAnimation(null);
}
}

clock.jpg
Place the following image in drawable folder.
clock.jpg
1011
like
0
dislike
0
mail
flag

You must LOGIN to add comments