Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private CustomListView1 As CustomListView
End Sub
Public Sub Initialize
End Sub
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
For i = 1 To 100
CustomListView1.Add(CreateItem, "")
Next
End Sub
Private Sub CreateItem As B4XView
Dim p As B4XView = xui.CreatePanel("")
p.SetLayoutAnimated(0, 0, 0, CustomListView1.AsView.Width, Rnd(40dip, 100dip))
Dim child As B4XView = xui.CreatePanel("")
p.AddView(child, 10dip, 2dip, Rnd(p.Width / 2, p.Width - 20dip), p.Height - 4dip)
child.SetColorAndBorder(0, 1dip, 0, 20dip)
Return p
End Sub
Private Sub CustomListView1_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
For i = FirstIndex To LastIndex
Dim raw As CLVItem = CustomListView1.GetRawListItem(i)
Dim pnl As B4XView = raw.Panel.GetView(0)
pnl.GetView(0).Color = PositionToColor(raw.Offset - CustomListView1.sv.ScrollViewOffsetY)
Next
End Sub
Private Sub PositionToColor(offset As Int) As Int
Dim StartR As Int = 0xFF
Dim StartG As Int = 0x00
Dim StartB As Int = 0xD6
Dim EndR As Int = 0x00
Dim EndG As Int = 0x00
Dim EndB As Int = 0xFF
Dim f As Float = Max(0, Min(1, offset / CustomListView1.sv.Height))
Dim r As Int = Bit.And(0xff, StartR + (EndR - StartR) * f)
Dim g As Int = Bit.And(0xff, StartG + (EndG - StartG) * f)
Dim b As Int = Bit.And(0xff, StartB + (EndB - StartB) * f)
Return xui.Color_ARGB(255, r, g, b)
End Sub