https://www.b4x.com/android/forum/threads/slide-activity.29162/
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
Activity 2 - Named 'Main2'Code:Sub Activity_Create(FirstTime As Boolean) Activity.LoadLayout("Main") 'name of my layout file, so it displays something on the screenEnd 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 leftEnd Sub
Main2:
Code Module:Code:Sub Activity_Create(FirstTime As Boolean) Activity.LoadLayout("Main2") 'name of my layout file, so it displays something on the screenEnd 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
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')Code: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
file1.xml:
file2.xml:Code:<?xml version="1.0" encoding="utf-8"?> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="1000" android:fromXDelta="0%" android:toXDelta="100%" />
file3.xml:Code:<?xml version="1.0" encoding="utf-8"?> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="1000" android:fromXDelta="-100%" android:toXDelta="0%" />
file4.xml:Code:<?xml version="1.0" encoding="utf-8"?> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="1000" android:fromXDelta="100%" android:toXDelta="0%" />
Code:<?xml version="1.0" encoding="utf-8"?> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="1000" android:fromXDelta="0%" android:toXDelta="-100%" />
Комментариев нет:
Отправить комментарий