Android Question Panel rotation (setRotationY)

Mark Stuart

Active Member
Licensed User
Longtime User
I have this code from the forum to rotate the panel on its Y axis:



B4X:
Sub Class_Globals
    Dim pnl As B4XView     'pnl is on a Layout
End Sub

Sub btnRotate_Click
    For i = 0 To 360
        setRotationY(pnl,i)
        Sleep(0)
    Next
End Sub

'Angle = rotation angle in degrees
Sub setRotationY(v As View, Angle As Float)
    Dim jo = v As JavaObject
    jo.RunMethod("setRotationY", Array As Object(Angle))
End Sub

The rotation takes almost 6 seconds to rotate. Without the Sleep(0), you don't see any animation (rotation) of the Panel (pnl), which is desired.
I've tried the Animation library, but it does not rotate the Panel on its Y axis.
Also, the pnl.SetRotationAnimated(1000,360) doesn't rotate on the Y axis.

The rotation duration desired would be 500 to 1000 milliseconds.

Any suggestions would be appreciated.
Mark Stuart
 
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
I have not looked or used the library but can probably be done with a bit of inline Java code or using JavaObject:

B4X:
    ObjectAnimator rotateAnimator = ObjectAnimator.ofFloat(myView, "rotation", 0f, 360f);
    rotateAnimator.setDuration(1000);
    rotateAnimator.setRepeatCount(ObjectAnimator.INFINITE);
    rotateAnimator.setRepeatMode(ObjectAnimator.RESTART);
    rotateAnimator.start();

You might have to import ObjectAnimator into the inline Java code

But I guess there might be an easier (pure b4a) solution somewhere on the forum that I have not seen
 
Last edited:
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I have not looked or used the library but can probably be done with a bit of inline Java code or using JavaObject:

B4X:
    ObjectAnimator rotateAnimator = ObjectAnimator.ofFloat(myView, "rotation", 0f, 360f);
    rotateAnimator.setDuration(1000);
    rotateAnimator.setRepeatCount(ObjectAnimator.INFINITE);
    rotateAnimator.setRepeatMode(ObjectAnimator.RESTART);
    rotateAnimator.start();

You might have to import ObjectAnimator into the inline Java code

But I guess there might be an easier (pure b4a) solution somewhere on the forum that I have not seen
I know I should look on the site, Joahn 😊 but... how do you pass the view to that code (and what type should it be)?
 
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime User
I know I should look on the site, Joahn 😊 but... how do you pass the view to that code (and what type should it be)?
My first try would be to pass the B4A view as is...else as an Object.....
 
Upvote 0

Mark Stuart

Active Member
Licensed User
Longtime User
I finally got the code to work on the Y axis.
See the code I pasted in post #6 on THIS post made by Erel from last year.

Result: rotating 360 degrees - a panel sized 40x40 with the radius set to 40 - a circle.
In the panel is placed a Label. The label text is a character, the first initial of a word.
The panel and the label rotate together on the Y axis (vertical) 360 degrees.
The panel is a view on or in a main panel on a CustomListView.
I've been wanting to get this feature for a long time.
Now it works.
 
Last edited:
Upvote 0
Top