This short tutorial will explain how to create custom transitions between activities.
The transitions must be declared in an XML file as described here: Animation Resources | Android Developers
1. Declare the transition
You should put the animation files under Objects\Res\anim folder.
The files must be set to be read-only. Otherwise they will be deleted.
After changing the files you should click on Tools - Clean Project. This will cause the IDE to recreate the resources mapping file (R.java).
2. Call SetAnimation
You should add this code to your project (requires Reflection library):
After calling StartActivity or Activity.Finish you should call SetAnimation.
For example:
The attached example demonstrates the transition. You should press on Connect and then on one of the images.
Pressing on the back key when the second activity is visible will also start a transition.
The animations are based on this example: Animation.java | Android Developers
The transitions must be declared in an XML file as described here: Animation Resources | Android Developers
1. Declare the transition
You should put the animation files under Objects\Res\anim folder.
The files must be set to be read-only. Otherwise they will be deleted.
After changing the files you should click on Tools - Clean Project. This will cause the IDE to recreate the resources mapping file (R.java).
2. Call SetAnimation
You should add this code to your project (requires Reflection library):
B4X:
Sub SetAnimation(InAnimation As String, OutAnimation As String)
Dim r As Reflector
Dim package As String
Dim in, out As Int
package = r.GetStaticField("anywheresoftware.b4a.BA", "packageName")
in = r.GetStaticField(package & ".R$anim", InAnimation)
out = r.GetStaticField(package & ".R$anim", OutAnimation)
r.Target = r.GetActivity
r.RunMethod4("overridePendingTransition", Array As Object(in, out), Array As String("java.lang.int", "java.lang.int"))
End Sub
After calling StartActivity or Activity.Finish you should call SetAnimation.
For example:
B4X:
StartActivity(Activity2)
SetAnimation("zoom_enter", "zoom_exit") 'without the xml extension
The attached example demonstrates the transition. You should press on Connect and then on one of the images.
Pressing on the back key when the second activity is visible will also start a transition.
The animations are based on this example: Animation.java | Android Developers