[B4X] [XUI] AS ViewPager based on xCustomListView
Hey, thanks to @KZero for his good zPager class, i was able to extract a few things from it to make this cross platform view. I spend a lot of time in creating views, some views i need by my self, but some views not and to create a high quality view cost a lot of time. If you want to support...
www.b4x.com
A small example project on how to achieve endless scrolling in both directions with the as viewpager.
Important
You need AS ViewPager V2.01+
and for B4J, you need V1.02+ of the jPager
The best thing is, it works in both directions
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("frm_main")
ASViewPager1.LazyLoading = True
ASViewPager1.LazyLoadingExtraSize = 4
For i = 0 To 20
Dim tmp_xpnl As B4XView = xui.CreatePanel("tmp_xpnl")
tmp_xpnl.Color = xui.Color_ARGB(255,Rnd(1,255),Rnd(1,255),Rnd(1,255))
tmp_xpnl.SetLayoutAnimated(0,0,0,ASViewPager1.Base.Width,ASViewPager1.Base.Height)
ASViewPager1.AddPage(tmp_xpnl,"Test" & i)
Next
#IF B4A
Sleep(250)
#Else
Sleep(0)
#End If
ASViewPager1.CurrentIndex = 10
ASViewPager1.Commit
B4XPages.SetTitle(Me,"Page " & (ASViewPager1.CurrentIndex +1) & "/" & ASViewPager1.Size)
End Sub
Private Sub ASViewPager1_PageChanged2(NewIndex As Int, OldIndex As Int)
If NewIndex <= OldIndex Then
If NewIndex <= 2 Then
Dim tmp_xpnl As B4XView = xui.CreatePanel("tmp_xpnl")
tmp_xpnl.Color = xui.Color_ARGB(255,Rnd(1,255),Rnd(1,255),Rnd(1,255))
tmp_xpnl.SetLayoutAnimated(0,0,0,ASViewPager1.Base.Width,ASViewPager1.Base.Height)
ASViewPager1.AddPageAt(0,tmp_xpnl,"")
End If
Else
If NewIndex = ASViewPager1.Size -2 Then
Dim tmp_xpnl As B4XView = xui.CreatePanel("tmp_xpnl")
tmp_xpnl.Color = xui.Color_ARGB(255,Rnd(1,255),Rnd(1,255),Rnd(1,255))
tmp_xpnl.SetLayoutAnimated(0,0,0,ASViewPager1.Base.Width,ASViewPager1.Base.Height)
ASViewPager1.AddPage(tmp_xpnl,"")
End If
End If
Sleep(0)
B4XPages.SetTitle(Me,"Page " & (NewIndex +1) & "/" & ASViewPager1.Size)
End Sub
Private Sub ASViewPager1_LazyLoadingAddContent(Parent As B4XView, Value As Object)
Dim xlbl As B4XView = CreateLabel
xlbl.Text = "Lazyloading Label"
xlbl.TextColor = xui.Color_White
xlbl.Font = xui.CreateDefaultBoldFont(20)
xlbl.SetTextAlignment("CENTER","CENTER")
Parent.AddView(xlbl,0,Parent.Height/2 - 50dip/2,Parent.Width,50dip)
End Sub
Private Sub CreateLabel As B4XView
Dim lbl As Label
lbl.Initialize("")
Return lbl
End Sub
Have Fun
Attachments
Last edited: