Android Question Best option to add a layout with size variable on CustomListView?

Alberto Iglesias

Well-Known Member
Licensed User
Hello all,

Anyone knows what's the best solution to put some layout with size variable on CustomListView?


My scenario:

I have a layout with one image, and this image is resizable according with width of screen, so, this image grow to keep square depending of width:

upload_2019-1-30_14-2-54.png


and I dont want to show this space on CustomListView between on row and another
upload_2019-1-30_14-4-25.png


the problem is this iHeight related below:

What's the best option to calculate the height of this new panel with this layout?

B4X:
    Dim p As Panel = xui.CreatePanel("")
    p.Initialize("")
    p.SetLayoutAnimated(  0, 0, 0, pCLV.AsView.Width, iHeight)
    pCLV.Add(p, "")
    p.LoadLayout(strLayout)

Thanks in advance
 

Alberto Iglesias

Well-Known Member
Licensed User
My solution was:

First, put this methods on CustomListView:

B4X:
public Sub SetScrollViewInnerHeight(Height As Double)
    sv.ScrollViewContentHeight = Height
End Sub

public Sub GetScrollViewInnerHeight() As Double
    Return sv.ScrollViewContentHeight
End Sub
and in the code, after loading the panel with layout, I decrease the height based on components of this new layout, look:

B4X:
    Dim dMax As Double
    For Each v As View In p.GetAllViewsRecursive
        If (v.Top + v.Height) > dMax Then dMax = v.Top + v.Height
    Next
    Dim iCLVHeight As Double = iHeight - (dMax+5dip)
    pCLV.SetScrollViewInnerHeight(pCLV.GetScrollViewInnerHeight - iCLVHeight)
Is working fine, but I need to know if is this a best pratice to do that!

upload_2019-1-30_14-23-1.png
 
Top