Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ViewFlipper 3D-Card-Flip

I started a new Android-App and I have one problem.

I want to code a ViewFlipper within some ImageViews. (Not really difficult)

The elements should turn (with this 3D-Flip anim.: http://www.inter-fuser.com/2009/08/android-animations-3d-flip.html) when the user is clicking on them. (I have already implemented this, too).

My idea only works for the first element in the ViewFlipper. I started to inflate this first view, but the new element doesn`t flip.

Is it possible to "clone/copy" the first view with its onclick events, so that the second view is flipping, too?

Thanks for help.

like image 623
Billabong Avatar asked Oct 03 '22 19:10

Billabong


2 Answers

The best and simplest solution is here: https://github.com/genzeb/flip

Use the flip transition in any of your ViewAnimator (such as ViewFipper) by doing:

AnimationFactory.flipTransition(viewFlipper, FlipDirection.LEFT_RIGHT);

like image 54
user846316 Avatar answered Oct 07 '22 19:10

user846316


You can use this as a sample, here's a object animator. :

    <?xml version="1.0" encoding="utf-8"?>
    <objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
        android:propertyName="rotationY"
        android:valueFrom="0"
        android:valueTo="360" >
    </objectAnimator>

I have noticed that some tutorial states only valueTo. That will allow you to flip only once since your view is already on 360 it won't flip anymore so always use valueFrom as well. And here's the code that will flip any view:

    public static void flip(Context context, View view) {
    ObjectAnimator anim = (ObjectAnimator) AnimatorInflater.loadAnimator(
            context, R.animator.flip);
    anim.setTarget(view);
    anim.setDuration(1000);
    anim.end();
    anim.start();
}
like image 38
Milan Avatar answered Oct 07 '22 20:10

Milan