Other Simple animations in B4A v4.00

Erel

Administrator
Staff member
Licensed User
Three new features that will soon be available:

1. Screen video recording based on the new ADB feature:

SS-2014-12-03_17.13.03.png


This feature requires an Android 4.4 device. It is very useful for demonstrations.

2. Simple animations. Three new methods were added to the View objects which make animations very simple:
View.SetLayoutAnimated - Similar to View.SetLayout. Allows you to change the view size and position. The change is animated.
View.SetVisibleAnimated - Similar to View.Visible. Fades in or out the view.
View.SetColorAnimated - Similar to View.Color. Animates the color change (based on the HSV color space).

See this video for an example (it looks smoother on the device), click on the small gear button and change to HD:


The complete code:
B4X:
Sub Globals
   Private btnMove As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("1")
End Sub
Sub btnHide_Click
   btnMove.SetVisibleAnimated(500, False)
End Sub

Sub btnShow_Click
   btnMove.SetVisibleAnimated(500, True)
End Sub

Sub btnMove_Click
   btnMove.SetLayoutAnimated(1000, Rnd(0, 90%x), Rnd(0, 90%y), Rnd(50dip, 200dip), Rnd(50dip, 200dip)) 
End Sub

Sub btnColors_Click
   Activity.SetColorAnimated(1000, Colors.White, Colors.Red)
End Sub

3. Layout animations. Layouts created with the designer are optionally animated. The animation is based on the views anchors:


Note that the animations are based on APIs introduced in Android 4.0. On older devices the methods changes will be applied without animations.
 

Troberg

Well-Known Member
Licensed User
A suggestion: It would be nice to have an event fired when the animation is complete. For example, one might want to "bounce" (making it larger, then smaller again) an object when it's clicked, or one might want to enable something or change the look when the movement is complete.

Chaining animations without that event is very difficult to do (one might use a timer, but two timers racing against each other does not seem like a sound programming practice...

Edit: Another example: Sometimes one wants to slide something out from the screen, the, once it's not visible, unload it.
 
Last edited:
Upvote 0

shashkiranr

Active Member
Licensed User
Hi Erel,

In my app i have created the layout through the code so how to apply Layout animations while exiting the app. Kindly let me know.

Regards,
SK
 
Upvote 0

Erel

Administrator
Staff member
Licensed User
This is a community forum. Please don't limit your questions to a single member.

The app exit is not a very good place to animate the layout as you don't have full control over the time it takes to hide your app.

You will need to go over the views and call View.SetLayoutAnimated to create an animation.
 
Upvote 0

Phayao

Active Member
Licensed User
Hello, i'm facing a strange (?) behavior with setlayoutanimated :
I want to move an imageview along a path defined by a series of x/y values. When i do this in a loop, the imageview jumps quickly to position 2 or 3 before moving slowly as desired.
B4X:
For i=0 to npoints ' is about 4 or 5
   iv.setlayoutanimated(2000, x(i), y(i),64dip,64dip)
next
I suspect that the loop does not wait for the first animations to complete and so i can see only the last part ?!
If so, how to stop the loop until the animation is completed ?
Or am I making a principle mistake here ? (probably no way to make chained animations with this event as mentioned before ?)
Any help is appreciated,

Chris
 
Last edited:
Upvote 0

BarryW

Active Member
Licensed User
Panel.SetLayoutAnimated
Panel.SetVisibleAnimated

How to capture animation end of this features...

Tnx...
 
Upvote 0
Top