Android Question How to create a customlistview with panels of different sizes?

asales

Expert
Licensed User
Longtime User
I use the panels with a scrollview, but I'm changing to a customlistview.

I use AutoScaleAll in the designer and if I use dip in Add of the customlistview, to a fixed height, I see diffences in the screen in a tablet and in a phone.

Because I don't know what is the height of the panel in different resolutions, I created the sub below to check the name of the panel in the layout and get the size.
So, I set the correct height of the panel used in the customlistview and works fine (in tablet and phone).
In this sub I need to create 2 panels and load the layout 2 times.

Is there a better way to make this?
B4X:
Sub CreateListItem(Lay As String, Width As Int, pnl As Panel) As Panel
    Dim p1 As B4XView = xui.CreatePanel("")
    p1.LoadLayout(Lay)
    p1.Height = pnl.Height
   
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, Width, p1.Height) 'correct height of panel to phone and tablet
    p.LoadLayout(Lay)

    Return p
End Sub

usage:
clv.Add(CreateListItem("resume", clv.AsView.Width, ResumePanel), 0)
clv.Add(CreateListItem("task", clv.AsView.Width, TaskPanel), 0)
 

LucaMs

Expert
Licensed User
Longtime User
Is there a better way to make this?
If it works, it is a good way to do it :)

I use a fixed height (dips) at runtime corresponding to the height of the "layout" of the item I create in the Designer, removing Autoscaleall only in this case, for the items.
[height of the "layout" because I take in account the bottom of the "lowest View" - damned english ?].

Trying to explain...
1603424395246.png


Item layout. EditText1 Top is 60dip, its height is 45dip, then the total height of the item is 105dip.
Autoscaleall removed for this layout.

The layout that will contain the xCLV usually has Autoscaleall. When I fill it at runtime, by creating the items, I create 105dip high panels.

xCLV.Add(CreateItem(..., 105dip, ...))

I'm not sure (but almost) this is the best or correct way to do it!


[Note: in the image, you can see just an example I created right now. I never keep the default and meaningless view names ;)]
 
Last edited:
Upvote 0
Top