over 8 years ago
In the below example code, I have set the animation to an ImagView when you clicks on image, image will rotate 180 degrees from Y axis. Here first, I have added an ImageView within actvity_main.xml layout, after that I have created a flip.xml resource file within animator folder and here I have added flip animation attributes, Now see programming part, here I have used AnimatorSet class and load flip.xml res. and used start() method for animation.
You can see below example code it clearly describes How to make Flip animation image in android
Step(1)-I have created flip.xml resource file within animator folder-
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:ordering="sequentially" >
<objectAnimator
android:duration="1000"
android:propertyName="rotationY"
android:valueFrom="0"
android:valueTo="180" >
</objectAnimator>
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:ordering="sequentially" >
<objectAnimator
android:duration="1000"
android:propertyName="rotationY"
android:valueFrom="0"
android:valueTo="180" >
</objectAnimator>
</set>
Step(2)-MainActivity-
final ImageView imageView = (ImageView) findViewById(R.id.imageview);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
set=(AnimatorSet)AnimatorInflater.loadAnimator(MainActivity.this,R.animator.flip);
set.setTarget(imageView);
set.start();
}
});
final ImageView imageView = (ImageView) findViewById(R.id.imageview);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
set=(AnimatorSet)AnimatorInflater.loadAnimator(MainActivity.this,R.animator.flip);
set.setTarget(imageView);
set.start();
}
});
Can you help out the community by solving one of the following Automation problems?
Do activity (Answer, Blog) > Earn Rep Points > Improve Rank > Get more opportunities to work and get paid!
For more topics, questions and answers, please visit the Tech Q&A page.
0 Comment(s)