Android Question B4XView.SetRoationAnimated ignores Pivot X/Y

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
If I set a view's PivotX and PivotY values with a JavaObject prior to invoking B4XView.SetRoation, it still rotates around the center of the view:
B4X:
    Dim poB4V As B4XView = lblRotate
    Dim j As JavaObject = lblRotate
    Dim X As Float = lblRotate.Width ' make the pivot point the lower right-hand corner
    Dim y As Float = lblRotate.Height
    j.RunMethod("setPivotX", Array As Object(X))
    j.RunMethod("setPivotY", Array As Object(Y))
    poB4V.SetRotationAnimated(200, 0)
If I use the same JavaObject and call the "setRotation" method directly, the rotation is performed as expected on the requested pivot point (without the animation, of course).

Is there a method to make the SetRotationAnimated utilize a specific pivot point that I missed?
 

DonManfred

Expert
Licensed User
Longtime User
You set the PivotX and X at the lblRotate but you are using poB4V to animate????
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Is there a method to make the SetRotationAnimated utilize a specific pivot point that I missed?
No. It is possible with JavaObject. Another option is to put the view inside a transparent panel:

1603958273895.png


B4X:
Sub Button1_Click
    Dim btn As B4XView = Sender
    btn.Parent.SetRotationAnimated(500, btn.Parent.Rotation + 360)
End Sub
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
You set the PivotX and X at the lblRotate but you are using poB4V to animate????
My goal here, is to animate the rotation of the label at the lower right-hand corner, not its center. There is no pivotx/y property in the B4XView object, therefore: javaobject and setPivotX/setPivotY.

I could, I suppose, manually calculate the linear rotation angle over time and achieve what I am looking for with javaobject setRotation in a loop, but that seems overkill. I had been using @Informatix's animation library, which still works fine. I was in the process of seeing if I could replace it with the native XUI methods and simplify the class in the process.

No. It is possible with JavaObject. Another option is to put the view inside a transparent panel:
Thank you, that confirms my suspicion! I'll take this opportunity to suggest adding a PivotX / PivotY property to the B4XView object ;)
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
I know what you mean, we had to make a class with these properties manipulating the smooth rotation times.

The post example uses timer.


 
Last edited:
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
I know what you mean, we had to make a class with these properties manipulating the smooth rotation times.
Thanks for the links! I'm currently using @Informatix's Excellent AnimationPlus library, for which I wrote a helper class to simplify the animation overhead. It works well, I was attempting to see if I could just utilize the (new-to-me) built-in XUI methods to remove the library dependency at some point. Currently not enough of the underlying translation methods/properties are exposed to make that happen.
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
remove the library dependency at some point. Currently not enough of the underlying translation methods/properties are exposed to make that happen.

Do you mean in case of migrating your application to B4i or B4J?
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
Our focus currently is B4A only, I was just hoping to "freshen up" the app and take advantage of the new features. For the app in question it was written long before resumable subs were available (early 2015 IIRC).
 
Upvote 0
Top