Android Question Panel.Height: Release -> Ok, Debug -> not ok

Discussion in 'Android Questions' started by KMatle, Feb 25, 2015.

  1. KMatle

    KMatle Expert Licensed User

    In a lot of my apps I use a Scrollview and put views dynamically on it. Today I've found a strange behaviour (B4A 4.30). Maybe I'm blind, but...

    In release mode the panel's height is adjusted correctly (tested on 2 devices), in debug (both modes), it will not change (stays at 1000dip). Any ideas?


    Code:
    CMSsv.Initialize2(1000dip,"CMSsv"
    Activity.AddView(CMSsv,0,0,100%x,100%y)
    later

    Code:
    toppos=1%y
            
    For i = eArtikel To lArtikel
               
                Artikel=ArtikelListe.get(i)
                filen=Artikel.Get(
    "ImageFile")
             
                
    Dim ueb As Label
                ueb.Initialize(
    "")
                ueb.Text=Artikel.Get(
    "Ueberschrift")
                ueb.Gravity=
    Gravity.CENTER
                ueb.Color=
    Colors.DarkGray
                ueb.TextColor=
    Colors.ARGB(255,255,165,0)
                CMSsv.Panel.AddView(ueb,
    5%x,toppos,90%x,5%y)
                SetLabelTextSize(ueb,ueb.Text)
               
                toppos=toppos+
    5%y
                
    Dim ueb2 As Label
                ueb2.Initialize(
    "")
                ueb2.Text=Artikel.Get(
    "OnlineAb") & "  " & i & " (" & Artikel.Get("Autor") &")"
                ueb2.Gravity=
    Gravity.left
                ueb2.Color=
    Colors.DarkGray
                ueb2.TextColor=
    Colors.ARGB(255,255,165,0)
                CMSsv.Panel.AddView(ueb2,
    5%x,toppos,90%x,3%y)
                SetLabelTextSize(ueb2,ueb2.Text)
               
                toppos=toppos+
    4%y
                
    Dim im As ImageView
                im.Initialize(
    "")
                im.Bitmap=
    LoadBitmap(mypath ,filen)
                im.Gravity=
    Gravity.CENTER
                CMSsv.Panel.AddView(im,
    5%x,toppos,44%x,30%y)
                
    Log(im.Width)
                
    Log(im.height)
               
                
    Dim te As Label
                te.Initialize(
    "")
                te.Text=Artikel.Get(
    "AText")
                te.Color=
    Colors.DarkGray
                te.TextColor=
    Colors.ARGB(255,255,165,0)
                CMSsv.Panel.AddView(te,
    50%x,toppos,45%x,30%y)
                SetLabelTextSize(te,te.Text)
                       
                toppos=toppos+
    32%y
           
            
    Next
            CMSsv.Panel.Height=toppos
     
  2. KZero

    KZero Active Member Licensed User

    working normally on both release and debug
     
  3. Erel

    Erel Administrator Staff Member Licensed User

  4. KMatle

    KMatle Expert Licensed User

    The reason for this behaviour is setting a breakpoint. I can reproduce it.

    Code:
    toppos=toppos+32%y
           
            
    Next
            
    --->>>>>   CMSsv.Panel.Height=toppos
       
       
            
    Log("Panel height: " &CMSsv.Panel.Height)
            
    Log("CMSSV height: " &CMSsv.Height)
    Setting it to "CMSsv.Panel.Height=toppos" seems to skip the line -> heigth not set

    So it's clear why it works in Release and not in Debug.

    @Erel : Is is a bug?
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    Have you tried to call requestLayout?
     
  6. KMatle

    KMatle Expert Licensed User

    Yes. It works (but adding code for debugging is not that comfortable)

    Without the code:

    -> Release: Everything is fine
    -> Debug + with breakpoint at the same line which adjusts the height: Doesn't work
    -> Debug + no breakpoint at the same line which adjusts the height: Everything is fine

    Does the debugger prevent it?

    Easiest solution: No breakpoint at the line which adjusts the panel's height.
     
    Cableguy likes this.
  7. Cableguy

    Cableguy Expert Licensed User

    Confusius once said... "if you know where the troubles are... why not just avoid them"?

    Well... maybe it was not confusius ...
     
    RandomCoder and KMatle like this.
  8. Erel

    Erel Administrator Staff Member Licensed User

    Seems like the message handling done by the debugger prevents the ScrollView from updating the height. However calling requestLayout may be needed in release mode as well (see the discussion in that link).
     
    KMatle likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice