Hello forum
I implemented a LazyLoading with a CLV by taking inspiration here: https://www.b4x.com/android/forum/threads/b4x-xui-customlistview-lazy-loading-virtualization.87930/
It works, but on old phones when i scroll the CLV it reads each picture at time when needed and in that moment the the Scrollview lags/bounces.
So i tryied to use a resumable sub to load the image and then appaly it to imageview in this way:
I was expecting (without success) to load the image from file in background without interrupting the UI avoiding in this way any lag.
My question is: is there a better approach to (lazy)load images leaving the UI responsive?
Thanks in advance for any suggestion!
I implemented a LazyLoading with a CLV by taking inspiration here: https://www.b4x.com/android/forum/threads/b4x-xui-customlistview-lazy-loading-virtualization.87930/
It works, but on old phones when i scroll the CLV it reads each picture at time when needed and in that moment the the Scrollview lags/bounces.
So i tryied to use a resumable sub to load the image and then appaly it to imageview in this way:
B4X:
Private Sub LoadPhoto
Dim Resumable_LoadPic As ResumableSub = LoadPic(ID)
Wait For(Resumable_LoadPic) Complete (Immagine As B4XBitmap)
Image_view.SetBitmap(Immagine)
End Sub
Private LoadPic(ID As String) As ResumableSub
Dim ImmagineRoundata As B4XBitmap = CreateRoundRectBitmap(xui.LoadBitmapResize(File.DirInternalCache, ID & ".jpg", Imageview.Width, Imageview.Height, True), 7dip)
Return ImmagineRoundata
End Sub
Sub CreateRoundRectBitmap (Input As B4XBitmap, Radius As Float) As B4XBitmap 'https://www.b4x.com/android/forum/threads/b4x-xui-rectangle-image-with-rounded-corners.86285/
Dim BorderColor As Int = xui.Color_White
Dim BorderWidth As Int = 0dip
Dim c As B4XCanvas
Dim xview As B4XView = xui.CreatePanel("")
xview.SetLayoutAnimated(0, 0, 0, Input.Width, Input.Height)
c.Initialize(xview)
Dim path As B4XPath
path.InitializeRoundedRect(c.TargetRect, Radius)
c.ClipPath(path)
c.DrawRect(c.TargetRect, BorderColor, True, BorderWidth) 'border
c.RemoveClip
Dim r As B4XRect
r.Initialize(BorderWidth, BorderWidth, c.TargetRect.Width - BorderWidth, c.TargetRect.Height - BorderWidth)
path.InitializeRoundedRect(r, Radius - 0.7 * BorderWidth)
c.ClipPath(path)
c.DrawBitmap(Input, r)
c.RemoveClip
c.Invalidate
Dim res As B4XBitmap = c.CreateBitmap
c.Release
Return res
End Sub
I was expecting (without success) to load the image from file in background without interrupting the UI avoiding in this way any lag.
My question is: is there a better approach to (lazy)load images leaving the UI responsive?
Thanks in advance for any suggestion!