Android Question Using SetLayoutAnimated to zoom in/out at a certain point

wimpie3

Well-Known Member
Licensed User
Longtime User
I'm trying to convert old code which was using nineoldandroids animations to the new SetLayoutAnimated function.

Nineoldandroids could zoom in and out around a certain point on the screen using setPivotX and setPivotY.

This isn't supported by SetLayoutAnimated - only left/top/width/height can be used - so I think I'll be needing transformation matrices.

I've already lost several hours trying to get the maths right... has anyone done this before?
 

wimpie3

Well-Known Member
Licensed User
Longtime User
Of course I have used the search function before asking my question. This is not what I'm looking for. I need to zoom in on a certain location, not on the center.
 
Upvote 0

wimpie3

Well-Known Member
Licensed User
Longtime User
Correct. What I want can be done with some maths using the standard functions of B4A, so I'd rather avoid using a library for that.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Private Sub Button1_Click
    Dim v As B4XView = Sender
    ScaleView(v, 1000, 2, v.Width, v.Height) 'bottom right corner
    Sleep(1000)
    ScaleView(v, 1000, 0.5, v.Width / 2, v.Height / 2) 'center
    Sleep(1000)
    ScaleView(v, 1000, 2, 0, 0) 'top left
End Sub

Private Sub ScaleView(View As B4XView, Duration As Int, ScaleRatio As Float, PivotX As Int, PivotY As Int)
    Dim dx As Float = ScaleRatio * PivotX - PivotX
    Dim dy As Float = ScaleRatio * PivotY - PivotY
    View.SetLayoutAnimated(Duration, View.Left - dx, View.Top - dy, _
        View.Width * ScaleRatio, View.Height * ScaleRatio)
End Sub
 
Upvote 0

wimpie3

Well-Known Member
Licensed User
Longtime User
Thank you so much @Erel, this works fine!

Just a little side-remark. I have no clue on how SetLayoutAnimated works behind the curtains, but since it's the only way we can animate views on all three platforms, would it be possible to add some kind of (optional) easing on the animation? That would give the animations a more professional look. Thanks!

Also: how can the animation be stopped? It seems that when the view gets removed WHILE the animation is playing, the animation is stopped as well. Is this correct?
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…