Create a 'anim' folder under res folder
Create a rotate.xml file under anim folder
add below code in rotate.xml
-------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate android:fromDegrees="0"
android:toDegrees="180"
android:pivotX="50%"
android:pivotY="50%"
android:duration="600"
android:interpolator="@android:anim/cycle_interpolator"/>
</set>
open your main.xml file and add an ImageView in it
-----------------------------------------------------------
<ImageView
android:id="@+id/swapImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_launcher"/>
open your MainActivity.java file
---------------------------------------------------
public class MainActivity extends Activity implements AnimationListener{
Animation animRotate;
ImageView swapImage;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
swapImage=(ImageView)findViewById(R.id.swapImage);
animRotate = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.rotate);
animRotate.setAnimationListener(this);
swapImage.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
swapImage.startAnimation(animRotate);
}
});
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
}
Create a rotate.xml file under anim folder
add below code in rotate.xml
-------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate android:fromDegrees="0"
android:toDegrees="180"
android:pivotX="50%"
android:pivotY="50%"
android:duration="600"
android:interpolator="@android:anim/cycle_interpolator"/>
</set>
open your main.xml file and add an ImageView in it
-----------------------------------------------------------
<ImageView
android:id="@+id/swapImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_launcher"/>
open your MainActivity.java file
---------------------------------------------------
public class MainActivity extends Activity implements AnimationListener{
Animation animRotate;
ImageView swapImage;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
swapImage=(ImageView)findViewById(R.id.swapImage);
animRotate = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.rotate);
animRotate.setAnimationListener(this);
swapImage.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
swapImage.startAnimation(animRotate);
}
});
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
}
No comments:
Post a Comment