Android Question [Solved] Resize CustomListView with a one long panel

asales

Expert
Licensed User
Longtime User
I tried several codes in the forum to resize a CLV after load a layout with a long panel, without success.
There are 3 labels in the long panel (top, middle and bottom) and I can't scroll the CLV to see the bottom label.
1772758236952.png

My example is in attach.

How can I fix it?
Thanks in advance for any tips.
 

Attachments

  • CLVOnePanel.zip
    15.5 KB · Views: 37

TILogistic

Expert
Licensed User
Longtime User
Are you using the Custom ListView for a single item?

And is this item taller than the visible area of the Custom ListView?

+++++++++++++
The typical problem when you have a single, very large item in a CustomListView is that the CustomListView incorrectly calculates the height when adding it, especially if you use LoadLayout or if the content changes afterward.

The safest solution is to add the panel, wait for the layout to calculate, and then resize the item.


This would cause CustomListView to recalculate the scroll area correctly.
B4X:
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0,0,0,clvTest.AsView.Width,clvTest.AsView.Height)

    p.LoadLayout("layout2")

    clvTest.Add(p,"")

    Sleep(0)

    Log(p.Height)
    Log(panel1.Height)

    clvTest.ResizeItem(0, panel1.Height)


test:
1.gif
 

Attachments

  • CLVOnePanel-test.zip
    4.3 KB · Views: 28
Last edited:
Upvote 1

PaulMeuris

Well-Known Member
Licensed User
And you could also try this from your code (added second and third line):
B4X:
    clvTest.Add(CreateListItem(Root.Width, Root.Height),-1)
    clvTest.ResizeItem(0,DipToCurrent(Root.Height))
'    clvTest.ResizeItem(0,DipToCurrent(Root.Width))        ' in landscape orientation
The first item is resized.
I tested the code on my tablet and used the DipToCurrent to adjust the dip sizes.
In landscape orientation the width can be used in stead of the height.
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Techniques used and learned when loading the design into an element and controlling the displacement in the visible area of the customlistview based on its size.

1.gif
 
Upvote 0

asales

Expert
Licensed User
Longtime User
Are you using the Custom ListView for a single item?

And is this item taller than the visible area of the Custom ListView?
Yes. Yes.

It is a long form. I'm using ScrollView but now I try to port to B4i. This is why I'm using CLV.

Thanks @LucaMs, @TILogistic, @PaulMeuris.

The soluction of TILogistic works better in B4A and B4J.
I'm get struggled with this code in B4i, but I'll post in the correct forum.
 
Upvote 0

asales

Expert
Licensed User
Longtime User
The soluction to B4i is here:
"Make sure that the "handle resize event" option is unchecked in the item's layout file."
 
Upvote 0
Top