Android Question xCLV Width Remains Constant Despite Setting Random Width

Mahares

Expert
Licensed User
Longtime User
This is a hypothetical question for curiosity only. Using the below code the xCLV items height changes randomly as intended, but the item width remains the same no matter what change I make to customlistview, panel or the items:
B4X:
Sub CreateMyItems() As B4XView
    Dim p As B4XView = xui.CreatePanel("")
'    p.SetLayoutAnimated(0,0,0,CustomListView1.AsView.Width,Rnd(75dip, 151dip))
    p.SetLayoutAnimated(0,0,0,Rnd(100dip, 251dip),Rnd(75dip, 151dip))
    p.LoadLayout("Item")
Why is that. Is there a way to vary the width of the panel from item to item.
 

Mahares

Expert
Licensed User
Longtime User
Per Erel's advice, I tried to have a random size panel layout and have it superimposed by the xCLV transparent cell items layout, but it looks so bad, I am showing the code, but I don't know if there is any way to make it worth while.
B4X:
Sub Globals
    Private xui As XUI
    Private CustomListView1 As CustomListView

    Private switch As B4XSwitch
    Private Label1 As Label
    Private z, t As Int  't= panel top, z is xClv height
    Private w As Int 'color of panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("laymain")  'has CustomListView1
    PopulateCLV
End Sub

Sub CreateRandomSizePanels( y As Int)  'y is height of panel
        Dim p As Panel
        p.Initialize("")
        Activity.AddView(p,0, t ,Rnd(100dip, 201dip), y)
        Dim px As B4XView =p
        w  =xui.Color_RGB(Rnd(0,256),Rnd(0,128),Rnd(0,256))
        px.SetColorAndBorder(xui.Color_ARGB(0,245,200,128),5dip, w, 5dip)
'        p.Color=Colors.ARGB(70,245,200,128)
End Sub

Sub PopulateCLV
    For i = 0 To 19
        Dim y As Int =Rnd(45dip, 85dip)
        If i>0 Then
            t=t +y 
        End If
        z=y        
        CreateRandomSizePanels( y)        
        Dim s As String = "This is symptom " & (i+1)
        CustomListView1.Add(CreateMyItems(s),i)            
    Next
End Sub

Sub CreateMyItems(s As String) As B4XView    'Problem with this sub
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0,0,0,CustomListView1.AsView.Width,z)
    Label1.Text= s
    Label1.TextColor =w
    Return p
End Sub
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Attached is a snapshot. I think I am not doing it correctly and exhibiting poor craftsmanship.. You can see that the panels (boxes with different color borders) are not superimposed by the items. Only the xClv scrolls. The panels are stationary and are not synchronized with the items on the xCLV. I have the full project I can post although the code I have in post #1 has the most relevant snippet.
 

Attachments

  • xClvwithRandomItemWidths.png
    23.5 KB · Views: 133
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is what I meant:



B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    For i = 1 To 100
        Dim p As B4XView = xui.CreatePanel("")
        p.SetLayoutAnimated(0, 0, 0, CustomListView1.AsView.Width, 100dip)
        p.Color = xui.Color_Transparent
        Dim p2 As B4XView = xui.CreatePanel("")
        p.AddView(p2, 0, 0, Rnd(100dip, p.Width), p.Height)
        p2.LoadLayout("Item")
        Label1.Text = $"Attached is a snapshot. I think I am not doing it correctly and exhibiting poor craftsmanship.. You can see that the panels (boxes with different color borders) are not superimposed by the items. Only the xClv scrolls. The panels are stationary and are not synchronized with the items on the xCLV. I have the full project I can post although the code I have in post #1 has the most relevant snippet."$
        CustomListView1.Add(p, "")
    Next
End Sub
 

Attachments

  • Project.zip
    15 KB · Views: 123
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…