iOS Question Problem in scrollview and panel height

Pooya1

Active Member
Licensed User
After add many view in panel and add panel height for scrollview contentheight,panel height change to 10

my code is :
B4X:
pnltags.Height = Top
sv1.ContentHeight = sv1.ContentHeight + pnltags.Height

In relate code,i set top (equal panel height) and so change scrollview contentheight
Before change contentheight,panel height is 300 but after change contentheight,panel height change to 10
Why?
 

Pooya1

Active Member
Licensed User
Hard to say without seeing your code. Add some log messages to understand when it changes.

In most cases it is easier to work with xCustomListView instead of ScrollView.
It didn't show log
But i attach my code
B4X:
Sub ShowTags
    
    If Tags.Size = 0 Then Return
    
    Dim bg As ColorDrawable
    bg.Initialize(Colors.RGB(Rnd(1,255),Rnd(1,255),Rnd(1,255)),20)
    
    Dim lbl As Label
    lbl.Initialize("")
    lbl.TextAlignment    =    lbl.ALIGNMENT_CENTER
    lbl.TextColor    = Colors.Black
    lbl.Text        = "Information"
    lbl.Color        = Colors.RGB(243,243,243)
    lbl.Font        = Library.GetFont(16)
    pnltags.AddView(lbl,0,0,pnltags.Width,50dip)
    Top = 50dip
    
    Dim lbdivider As Label
    lbdivider.Initialize("")
    lbdivider.Color = Colors.ARGB(100,240, 240, 240)
    pnltags.AddView(lbdivider,10dip,Top,pnltags.Width-20dip,1dip)
    
    Top = Top + 10dip
    
    For i = 0 To Tags.Size - 1
        
        Dim data As Map
        data    =    Tags.Get(i)
        
        Dim lbl2 As Label
        lbl2.Initialize("")
        lbl2.TextAlignment    =    lbl.ALIGNMENT_RIGHT
        lbl2.TextColor        = Colors.Black
        lbl2.Text            = (i + 1) & ": " & data.Get("sValue")
        lbl2.Font            = Library.GetFont(16)
        pnltags.AddView(lbl2,10dip,Top,pnltags.Width-20dip,30dip)
        Top = Top + 30dip
        
        Dim values(),val As String
        val = data.Get("sTagValue")
        
        If val.IndexOf(",") > -1 Then
            
            values = Regex.Split(",",val)
            
            Dim cd As ColorDrawable
            cd.Initialize(Colors.RGB(238, 238, 238),9dip)
            
            For j = 0 To values.Length - 1
                
                Dim title As String
                title = values(j)
                
                Dim rb As Switch
                rb.Initialize("switch")
                pnltags.AddView(rb,100%x-70dip,Top,50dip,30dip)
                rb.Tag            =    Array(data.Get("sTitle"),values(j))
                
                Switchs.Add(rb)
                
                Dim lbl4 As Label
                lbl4.Initialize("aa")
                lbl4.TextAlignment    =    lbl4.ALIGNMENT_RIGHT
                lbl4.TextColor    = Colors.Black
                lbl4.Text        = title
                lbl4.Font        = Library.GetFont(13)
                pnltags.AddView(lbl4,0,Top,100%x-80dip,30dip)
                
                rb.BringToFront
                
                Top = Top + lbl4.Height + 8dip
                
            Next
            
            Top = Top + 40dip
            
            Dim lbdivider As Label
            lbdivider.Initialize("")
            lbdivider.Color = Colors.ARGB(100,240, 240, 240)
            pnltags.AddView(lbdivider,5dip,Top,pnltags.Width - 10dip,1dip)
            Top = Top + 10dip
            
        Else
            lbl2.Text = lbl2.Text
            
            Dim lblvalue As Label
            lblvalue.Initialize("")
            lblvalue.TextColor    = Colors.Black
            lblvalue.TextAlignment    =    lbl4.ALIGNMENT_CENTER
            lblvalue.Font        =    Library.GetFont(15)
            lblvalue.Text        = val
            
            pnltags.AddView(lblvalue,10dip,lbl2.Top,70dip,30dip)
            
            Dim lbdivider As Label
            lbdivider.Initialize("")
            lbdivider.Color = Colors.ARGB(100,240, 240, 240)
            pnltags.AddView(lbdivider,10dip,lbl2.Top + 38dip,pnltags.Width-20dip,1dip)
            
            Dim canvas As Canvas
            canvas.Initialize(lblvalue)
            lblvalue.Width = Page1.RootPanel.Width
            
            Dim cd As ColorDrawable
            cd.Initialize(Colors.RGB(219,219,219),lblvalue.Width/3.2)
            cd.Apply(lblvalue)
            
            Top = Top + 20dip
            
        End If
            
    Next

    pnltags.Height = Top
    sv1.ContentHeight = sv1.ContentHeight + pnltags.Height
    btnadd2cart.Top = pnltags.Height + pnltags.Top
    
End Sub

When i use sv1.ContentHeight = sv1.ContentHeight + pnltags.Height,pnltags height change to 10
 
Upvote 0

Pooya1

Active Member
Licensed User
What is ColorDrawable?

As I previously wrote you should use xCustomListView. It is very powerful and simple to work with.
ColorDrawable is class that when i move b4a project to b4i,there is no problem
Yes i know xCustomListView is good,but i add one normal layout to scrollview (my scrollview not is list)
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
ColorDrawable is class that when i move b4a project to b4i,there is no problem
Try XUI library.

Hard to say anything from this code. If you are unable to read the logs then you should first solve it.

The only thing that I can say is that you are creating canvases, do not use them and never release them as you should.
 
Upvote 0

Pooya1

Active Member
Licensed User
Try XUI library.

Hard to say anything from this code. If you are unable to read the logs then you should first solve it.

The only thing that I can say is that you are creating canvases, do not use them and never release them as you should.
Yes you right
I have question
With change scrollview contentheight,maybe affect on other view size?
 
Upvote 0

Pooya1

Active Member
Licensed User
If you are loading a layout to the inner panel then the layout will be resized. You can disable it by unchecking "Handle resize events" in the layout file.
Yes it is,i disable "Handle resize events"
Thanks so much
 
Upvote 0

Pooya1

Active Member
Licensed User
I use below code and it is working now
B4X:
pnltags.Height = Top
sv1.ContentHeight = sv1.ContentHeight + Top
Sleep(500)
sv1.ContentHeight = sv1.ContentHeight + Top
It is working but i dont know why working when i use Sleep(500)
 
Upvote 0
Top