what i want is, when the user open the 2nd activity, the activity slides from right-to-left. and when use return back to 1st activity, the activity slider from left-to-right.
The following will allow you to tap on a button and it will load the new Activity, and while the new activity loads it will animate the view left and right.
Activity 1- Named 'Main'
'Main2' is the name of my Activity that I want to load, when I tap on the button
B4X:
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Main") 'name of my layout file, so it displays something on the screen
End Sub
Sub Button1_Click
StartActivity(Main2)
SetAnimation("file3", "file4") 'move the current Activity to the left, and the new activity will come from the right and will scroll to the left
End Sub
Activity 2 - Named 'Main2'
Main2:
B4X:
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Main2") 'name of my layout file, so it displays something on the screen
End Sub
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
If KeyCode = KeyCodes.KEYCODE_BACK Then
Activity.Finish
SetAnimation("file2", "file1") 'move the current Activity to the right, and the new (or known as the old Activity) will come from the left and will scroll to the right
Return True
End If
End Sub
Code Module:
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
The following XML files need to be placed in ..\Objects\res\anim folder and all need to be set to 'Read-Only' (right hand mouse on the file and select 'properties' then tick the box that says 'Read-Only')