I have tired to make a flip card in android.Please make an image view,when I click on,it flip like
You can flip a layout by setting the View property scaleX to -1. So View#setScaleX(1f) is normal, and View#setScaleX(-1f) is flipped (visually).
Use clearAnimation() to stop an animation.
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final ObjectAnimator oa1 = ObjectAnimator.ofFloat(imageView, "scaleX", 1f, 0f);
final ObjectAnimator oa2 = ObjectAnimator.ofFloat(imageView, "scaleX", 0f, 1f);
oa1.setInterpolator(new DecelerateInterpolator());
oa2.setInterpolator(new AccelerateDecelerateInterpolator());
oa1.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
imageView.setImageResource(R.drawable.frontSide);
oa2.start();
}
});
oa1.start();
}
});
This animation doesn't have any depth but maybe you will like it.
You can also set animation duration with
oa1.setDuration(1000);
oa2.setDuration(1000);
Property Animations (not to be confused with the older View Animation) are quite powerful :
final View v = <the_image_view>;
// first quarter turn
v.animate().withLayer()
.rotationY(90)
.setDuration(300)
.withEndAction(
new Runnable() {
@Override public void run() {
<change the image...>
// second quarter turn
v.setRotationY(-90);
v.animate().withLayer()
.rotationY(0)
.setDuration(300)
.start();
}
}
).start();
You can adjust the perspective effect with View.setCameraDistance()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With