- Get link
- X
- Other Apps
- Get link
- X
- Other Apps
Animation in ImageView
You can provide animation also in ImageView,
with the help of RotateAnimation:
In Activity,
drag and drop an ImageView and set any Image you desire.
Now, the main part is code file
In .java file
use the RotateAnimation as:
RotateAnimation ra = new RotateAnimation(0f, 350f, 15f, 15f);
ra.setInterpolator(new LinearInterpolator());
ra.setRepeatCount(Animation.INFINITE);
ra.setDuration(500);
To
Final code will be as:-
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="47dp"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
and MainActivity.java will be as
package com.example.animatetest;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
public class MainActivity extends Activity {
ImageView iv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv=(ImageView)findViewById(R.id.imageView1);
// Step1 : create the RotateAnimation object
RotateAnimation anim = new RotateAnimation(0f, 350f, 15f, 15f);
// Step 2: Set the Animation properties
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(700);
// Step 3: Start animating the image
iv.startAnimation(anim);
// Later. if you want to stop the animation
// image.setAnimation(null);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
You can provide animation also in ImageView,
with the help of RotateAnimation:
RotateAnimation (float fromDegrees, float toDegrees, float pivotX, float pivotY)
In Activity,
drag and drop an ImageView and set any Image you desire.
Now, the main part is code file
In .java file
use the RotateAnimation as:
RotateAnimation ra = new RotateAnimation(0f, 350f, 15f, 15f);
ra.setInterpolator(new LinearInterpolator());
ra.setRepeatCount(Animation.INFINITE);
ra.setDuration(500);
To
Final code will be as:-
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="47dp"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
and MainActivity.java will be as
package com.example.animatetest;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
public class MainActivity extends Activity {
ImageView iv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv=(ImageView)findViewById(R.id.imageView1);
// Step1 : create the RotateAnimation object
RotateAnimation anim = new RotateAnimation(0f, 350f, 15f, 15f);
// Step 2: Set the Animation properties
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(700);
// Step 3: Start animating the image
iv.startAnimation(anim);
// Later. if you want to stop the animation
// image.setAnimation(null);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
Comments
Post a Comment