I share this.
It is like sliding panels, but not using animation. It uses a horizontal scrollview. Code is really easy to understand and quite short.
It uses 3 panels. One for the previous page, one for the current page and one for the next.
Your code to load a page in the panel goes in: Page_Changed_Event(page As Int, panel_nr As Int)
Anyone has another easy alternative?
It is like sliding panels, but not using animation. It uses a horizontal scrollview. Code is really easy to understand and quite short.
It uses 3 panels. One for the previous page, one for the current page and one for the next.
Your code to load a page in the panel goes in: Page_Changed_Event(page As Int, panel_nr As Int)
Anyone has another easy alternative?
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private Current_Page=0 As Int 'current page, first page = 0
Private Number_of_Pages=25 As Int 'number of pages in the book
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim scrollview1 As HorizontalScrollView
Dim panels(3) As Panel
Dim timer1 As Timer
Dim firsttick As Boolean
End Sub
Sub Activity_Create(firstTime As Boolean)
firsttick=True
scrollview1.Initialize(300%x,"")
timer1.Initialize("timer1",250)
Activity.AddView(scrollview1,0,0,100%x,100%y)
For i=0 To 2
panels(i).Initialize("")
scrollview1.Panel.AddView(panels(i),i*100%x,0,100%x,100%y)
Next
End Sub
Sub Activity_Resume
timer1.Enabled=True
End Sub
Sub Activity_Pause (UserClosed As Boolean)
timer1.Enabled=False
End Sub
Sub Page_Changed_Event(page As Int, panel_nr As Int)
'Code to load data into the panels goes here
'example:
Dim m1 As String
m1="load page " & page & " in panel " & panel_nr
Activity.Title=m1
panels(panel_nr).RemoveAllViews
Dim label1 As Label
label1.Initialize("")
label1.Text="Page " & page
label1.Gravity=Gravity.CENTER
label1.TextSize=12+Ceil(30*(page/Number_of_Pages))
panels(panel_nr).AddView(label1,30%x,30%y,40%x,40%y)
End Sub
Sub timer1_tick
Dim nextpage,prevpage As Int
Dim looppanels=False
Dim left,middel,right As Int
For i=0 To 2
If panels(i).Left=0%x Then
left=i
Else If panels(i).Left=100%x Then
middel=i
Else
right=i
End If
Next
If firsttick Then
firsttick=False
nextpage=Current_Page+1
If nextpage>=Number_of_Pages Then
nextpage=0
End If
prevpage=Current_Page-1
If prevpage<0 Then
prevpage=Number_of_Pages-1
End If
scrollview1.ScrollPosition=0%x 'prevents flikkering
scrollview1.scrollposition=100%x
Page_Changed_Event(Current_Page,middel)
Page_Changed_Event(nextpage,right)
Page_Changed_Event(prevpage,left)
Else
If scrollview1.scrollposition<=0%x Then
scrollview1.scrollposition=0%x 'prevents flikkering
Current_Page=Current_Page-1
If Current_Page<0 Then
Current_Page=Number_of_Pages-1
End If
nextpage=Current_Page+1
If nextpage>=Number_of_Pages Then
nextpage=0
End If
prevpage=Current_Page-1
If prevpage<0 Then
prevpage=Number_of_Pages-1
End If
panels(left).Left=100%x
panels(middel).Left=200%x
panels(right).Left=0%x
Page_Changed_Event(prevpage,right)
scrollview1.scrollposition=100%x
Else If scrollview1.scrollposition>=200%x Then
scrollview1.scrollposition=200%x 'prevents flikkering
Current_Page=Current_Page+1
If Current_Page>=Number_of_Pages Then
Current_Page=0
End If
nextpage=Current_Page+1
If nextpage>=Number_of_Pages Then
nextpage=0
End If
prevpage=Current_Page-1
If prevpage<0 Then
prevpage=Number_of_Pages-1
End If
panels(left).Left=200%x
panels(middel).Left=0%x
panels(right).Left=100%x
Page_Changed_Event(nextpage,left)
scrollview1.scrollposition=100%x
End If
End If
End Sub