iOS Question B4XCustomListView Resizing Item Height Problem

walterf25

Expert
Licensed User
Longtime User
Hello everyone, i have noticed this issue before but never really bothered me as much as it is today, I have a layout with a few views, I also have a TextField, the height of this field is changed according to the Text Height, if the TextField is significantly large I also need to change the height of the overall Item, ie, the parent panel's height.

The problem i'm having is that while the same code works in the B4A version, it doesn't seem to work in the B4i version.
Here is the relevant code where the item is created.
B4X:
            Dim Panelheight As Int = 480dip
            c6IconEd.Visible = False
            
            Dim c6itemlabelnote2 As Label
            c6itemlabelnote2.Initialize("c6itemlabelnote")
            c6itemlabelnote2.Text = CbMap.GetDefault("note1", "")
            c6itemlabelnote2.SizeToFit
            c6itemlabelnote2.TextColor =  Colors.Blue 'Starter.MyColorBlack54
            c6itemlabelnote2.Multiline = True
            c6itemlabelnote2.Color = Starter.MyColorBlack05
            c6itemlabelnote2.Tag = CbMap
            c6itemlabelnote2.SetLayoutAnimated(0, 0, 0,0, c6itempanelback.Width, 20dip) ' MUST be here!!
            Dim S As String = c6itemlabelnote2.Text
            Dim c6labelhcalc As Int = S.MeasureHeight(Font.DEFAULT)
            LogColor("c6labelhcalc: " & c6labelhcalc, Colors.Blue)
            Dim PanelHeight2 As Int = PanelHeight + c6labelhcalc

            c6itempanelback.AddView(c6itemlabelnote2, 16dip, c6IconEd.top + 4dip, c6itempanelback.Width -32dip, c6labelhcalc)
            c6itemlabelnote2.Height = c6labelhcalc + 20dip
            If (c6itemlabelnote2.Top + c6itemlabelnote2.Height + 20dip) > PanelHeight Then
                p.Height = PanelHeight2
                LogColor("p.height: " & p.Height, Colors.Green)
                c6itempanelback.Height = p.Height
                c6itempanelframe.Height = c6itempanelback.Height
                ''c0tabCLV_c6list.ResizeItem(Index, PanelHeight2)
                ''Sleep(100)
            Else
            ''nothing here   
            End If

Basically the item only needs to be resized if the Textfield's height is large enough, the problem is that panel's height doesn't get resized after a certain height, i'm guessing after the 480dip that is originally set to, but why is that, I should be able to resize it's height to whatever height i want, what ends up happening is that i end up with a huge gap instead between the item that I want resized and the item below it.

Any thoughts on why that happens? as I mentioned i've noticed this issue before but never really thought about asking why this happens.

Thanks,
Walter
 

walterf25

Expert
Licensed User
Longtime User
1. SizeToFit will not work correctly if the width is not set.
2. CLV.AddTextItem will size the item based on the text.
3. If you are unable to solve it then please upload a small example.
Hi Erel, i have the following code:
B4X:
    Dim CbMap As Map = Starter.md.GetC6LogMap(c6data.DateString)
    If CbMap.Size = 0 Then
        CbMap.Put("id", c6data.DateString)
        CbMap.Put("parent_id", c6data.ExtraMap1.GetDefault("energy",""))
        CbMap.Put("note1", "")
    End If
    CbMap.Put("ClvIndex", Index)
    CbMap.Put("c6data", c6data)

    ' ----- ----- -----
    ' Layout
    ' ----- ----- -----
    Dim PanelHeight As Int = 120dip
    Dim p As Panel
    p.Initialize("")
    p.SetLayoutAnimated(0,0,0,0,c0tabCLV_c6list.AsView.Width, PanelHeight)
    ''p.Height = PanelHeight
    p.LoadLayout("clvitemc6bs")
    c6itemAction1.Visible = True

    c6itempanelframe.SetColorAndBorder(Starter.xui.Color_Transparent, 2dip, 0x9E00FFFF, 4dip) ' azure, cyan
    
    ' --- Moon
    c6itemimageview3Label.TextColor = Starter.MyColorBlack60

    ' --- Panel + frame
    If c6data.IsToday Then
        c6itempanelframe.Visible = True
        c6itempanelframe.SendToBack
    Else
        c6itempanelframe.Visible = False
    End If


    ' ----- ----- -----
    ' Content
    ' ----- ----- -----
    c6itempaneltop.Color = Starter.MyColorPrimaryLight
    c6itempaneltop.TextColor = Starter.TextColorLight
    c6itempaneltop.Text = "  " & c6data.DateString & " " & Starter.loc.Localize(c6data.WeekDayString)
    LogColor("c6itempaneltop.text: " & c6data.DateString & " " & Starter.loc.Localize(c6data.WeekDayString), Colors.Blue)
        
    ' --- Notes
    If CbMap.GetDefault("note1", "") <> "" Then
        c6IconEd.Visible = False
            
        Dim c6itemlabelnote2 As Label
        c6itemlabelnote2.Initialize("c6itemlabelnote")
        c6itemlabelnote2.Text = CbMap.GetDefault("note1", "")
        c6itemlabelnote2.Multiline = True
        c6itemlabelnote2.TextColor =  Colors.Blue 'Starter.MyColorBlack54
        c6itemlabelnote2.Color = Starter.MyColorBlack05
        c6itemlabelnote2.Tag = CbMap

        c6itempanelback.AddView(c6itemlabelnote2, 16dip, c6IconEd.top +4dip, c6IconEd.Width, c6itemlabelnote2.Text.MeasureHeight(Font.DEFAULT))
        Dim c6labelHcalc As Float = c6itemlabelnote2.Text.MeasureHeight(Font.DEFAULT) + 20dip
        Dim PanelHeight2 As Float = PanelHeight +c6labelHcalc
        c6itemlabelnote2.Height = c6labelHcalc + 40dip
        c6itemlabelnote2.Width = c6IconEd.Width
        p.Height = PanelHeight2 + 40dip
        c6itempanelback.Height = p.Height
        c6itempanelframe.Height = c6itempanelback.Height
    End If

What I'm trying to do is resize the c6itemlabelnote2 label to fit the text, and also resizing the main item panel to fit the newly resized c6itemlabelnote2 label, for some reason the main item panel doesn't seem to be resized instead i end up seeing a big gap between the bottom of the panel and the next item right below it.

Why is that, i'm sure is a coding mistake but i can't seem to figure out which part of my code is causing this issue.

I've seen this issue in B4A and B4i, it seems that the panel where the layout is being loaded can not be resized beyond the initial 120dip set at the beginning of the code.

Thanks,
Walter
 
Upvote 0
Top