Android Question Horizontal View Flip Animation

walterf25

Expert
Licensed User
Longtime User
Hello everyone, i need to create a smooth horizontal flip animation for any view, i have something more or less working using ICOSFlip3DView library which works great, the only problem is that i would like the animation to be even, what I mean by even is that when the panel or imageview rotates 180 degrees, there is always this effect around the top and bottom that looks as if view stretches, i've seen other tutorials online where they've made the animation even and smooth, i've tried following those tutorials but none of them have worked, one of them suggests changing the camera distance which I did using in-line java code but I don't see any changes.
here's a small video of what I have so far, notice around the top when the view rotates and you will see that it seems as if it stretches a bit.


and here is what i'm actually looking to accomplish, i realize i can easily wrap any of the libraries out there but i'm trying to find a solution that won't have to force me to add any more libraries to my project.

Here's the code I have
B4X:
Sub btn1_Click
''    a1 = xml.LoadAnimation("anim_animation", "in")
    ''a1.Duration = 2000
    ''a1.Start(pnl1)
    Private NativeMe As JavaObject
    NativeMe.InitializeContext
    Dim Distance As Float = 5000
    Log("distance: " & Distance)
    Log("scale0: " & GetDeviceLayoutValues.Scale)
    Dim scale As Float = NativeMe.RunMethod("Scale", Null)
    Log("scale: " & scale)
    increaseCameraDistance(pnl1, Distance, scale)
    If direction = False Then
        flip.Flip3DView("flip", pnl1, 180, 700, flip.FLIP_HORIZONTAL)
        ''a1.InitializeRotate("a1", 0, 180)
        ''a1.InitializeRotateCenter("a1", 0, 180, pnl1)
        pnl1.SetColorAnimated(700, Colors.blue, Colors.Green)
        ''a1.Duration = 2000
        ''a1.InitializeAlpha("a1", 0, 1)
        ''a1.Duration = 1000
        ''a1.Start(pnl1)
    Else
        flip.Flip3DView("flip", pnl1, 180, 700, flip.FLIP_HORIZONTAL)
        ''a1.InitializeRotate("a1", 0, 180)
        ''a1.InitializeRotateCenter("a1", 0, 180, pnl1)
        pnl1.SetColorAnimated(700, Colors.green, Colors.blue)
        ''        a1.Duration = 2000
        ''a1.InitializeAlpha("a1", 1, 0)
        ''a1.Duration = 1000
        ''a1.Start(pnl1)
        ''    pnl1.Color = Colors.blue
    End If
    
    ''float scale = context.getResources().getDisplayMetrics().density;
    ''view.setCameraDistance(Distance * scale);
    If a1.IsInitialized Then
        a1.Stop(pnl1)
        pnl1.Invalidate
        a1.Start(pnl1)
    End If
    flip.StartAnim(pnl1)
''   
End Sub

Sub increaseCameraDistance(v As View, Distance As Float, scale As Float)
    Dim jo = v As JavaObject
    Log("camera distance: " & Distance)
    jo.RunMethod("setCameraDistance", Array(Distance * scale))
End Sub

Thanks in advance all.
 

walterf25

Expert
Licensed User
Longtime User
Does the result change if you make the cameraDistance value really large ... set it for instance to 50000?
No it doesn't i've tried different values without any change.

Regards,
Walter
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Where is my post? :eek:

Simply I wrote it more than 1h ago, but I forgot to click on Post Reply (or I have not hit it :D):

https://www.b4x.com/android/forum/threads/nineoldandroids-or-designer.76535/
Using NineOldAndroid library works perfect, all you gotta do is add the code suggested by @Informatix
B4X:
Dim VH As noaViewHelper
VH.setPivotX(pnlByDesigner, pnlByDesigner.Width/2)
VH.setPivotY(pnlByDesigner, pnlByDesigner.Height/2)

I will try to post the results later on tonight.
thanks, everyone.
walter
 
Last edited:
Upvote 0
Top