Android Question What's wrong with this code?

junglejet

Active Member
Licensed User
Longtime User
Hello all, what's wrong with this code that I cannot see red panels on top of a scrollview.
Cannot see the trees in the forest...
Can't I nest a scrollview on a panel and a panel on a scrollview panel?
Thanks for your kind hints
Andy

B4X:
Dim pan As Panel
    Dim sv4 As Scrollview
    Dim PanelType as Int =3
    Dim panelbkcolor As Int =colors.white
    pan.Initialize("")
    Select PanelType
        Case 3
            sv4.Initialize(200%y)
            pan.AddView(sv4,0,0,100%x,100%y-20dip)
            pan.Color = panelbkcolor
            sv4.Panel.Color = panelbkcolor
            Dim h As Int
            h= sv4.Panel.width/2048*1536
            pncam1.Initialize("")
            sv4.Panel.AddView(pncam1,0,0,sv4.Panel.width,h)
            pncam2.Initialize("")
            sv4.Panel.AddView(pncam2,0,h+2dip,sv4.Panel.width,h)
            pncam3.Initialize("")
            sv4.Panel.AddView(pncam3,0,2*h+4dip,sv4.Panel.width,h)
            pncam1.Color=Colors.red
            pncam2.Color=Colors.red    
            pncam3.Color=Colors.red
End Select
 
Last edited:

junglejet

Active Member
Licensed User
Longtime User
You can nest scrollviews and panels.

Where is 'pan' added to your layout?

I have extracted the critical code. Pan is a Sliding Panel.
The code needs AnimateSlidingMenu.bas class to run

Thanks for any help

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    'Dim hc As HttpClient

    Dim FILL_PARENT As Int : FILL_PARENT = -1
    Dim WRAP_CONTENT As Int : WRAP_CONTENT = -2

    'We put this information to the panel tag of the panel for the pages
    Type PanelInfo (PanelType As Int, LayoutLoaded As Boolean)

    'Dim CurrentTheme As Int : CurrentTheme = 0
    Dim CurrentPage As Int : CurrentPage = 0

End Sub

Sub Globals

    Dim AsMenu, AsMenu1 As AnimatedSlidingMenu

    'The container and the ViewPager objects
    Dim container As AHPageContainer
    Dim pager As AHViewPager
    'Optionally you can use an AHViewPagerTabs object as a page indicator
    Dim tabs As AHViewPagerTabs
    'This panel is just for a colored line between the tabs and the pages.
    Dim line As Panel
    Dim pncam1,pncam2,pncam3 As Panel
    Dim sv4 As ScrollView
    Dim panelbkcolor As Int = Colors.Green
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.Color=Colors.white
    Activity.TitleColor=Colors.white
    Activity.Title="TEST"
   
    'Initialize the panels we use for the pages and put them in the container
    container.Initialize
    For i = 3 To 4
        Dim pan As Panel
        Select i
            Case 3
                pan = CreatePanel(i, "my photos")
                container.AddPage(pan,"my photos")
            Case 4
                pan = CreatePanel(i, "my images")
                container.AddPage(pan,"my images")
        End Select
    Next
    'Now we have a container with our panels just add it to the pager object
    pager.Initialize(container, "Pager")
        'As we want to show the tabs page indicator, we initialize it
    tabs.Initialize(pager)
    tabs.LineHeight = 5dip
    tabs.UpperCaseTitle = False
   
    'We add a line below the tab page indicator because it looks good
    Dim col As ColorDrawable
    col.Initialize(tabs.LineColorCenter, 0)
    line.Initialize("")
    line.Background=col

    Activity.AddView(tabs, 0, 0, FILL_PARENT, WRAP_CONTENT)
    Activity.AddView(line, 0, 35dip, Activity.Width, 2dip)
    Activity.AddView(pager, 0, 35dip + 2dip, Activity.Width, Activity.Height)
   
End Sub

'This creates a page of the given Type
Sub CreatePanel(PanelType As Int, Title As String) As Panel
    Dim pan As Panel
    Dim pi As PanelInfo
    pi.Initialize
    pi.LayoutLoaded = False
    pi.PanelType = PanelType
    pan.Initialize("")
    Select PanelType
        Case 3,4 'my photos
            sv4.Initialize(200%y)
            pan.AddView(sv4,0,0,100%x,100%y-20dip)
            pan.Color = panelbkcolor
            sv4.Panel.Color = panelbkcolor
            Dim h As Int
            h= sv4.Panel.width/2048*1536
            pncam1.Initialize("")
            pncam1.Color=Colors.red
            sv4.Panel.AddView(pncam1,0,0,sv4.Panel.width,h)
            pncam2.Initialize("")
            sv4.Panel.AddView(pncam2,0,h+2dip,sv4.Panel.width,h)
            pncam3.Initialize("")
            sv4.Panel.AddView(pncam3,0,2*h+4dip,sv4.Panel.width,h)
            pncam1.Color=Colors.red
            pncam2.Color=Colors.red
            pncam3.Color=Colors.red
    End Select
    pan.Tag = pi
    Return pan
End Sub
 
Upvote 0

junglejet

Active Member
Licensed User
Longtime User
Hi Erel,

this piece of code you mentioned is from the AHViewPager lib and it works well. (have replaced it by
Activity.AddView(tabs, 0, 0,100%x,35dip)' FILL_PARENT, WRAP_CONTENT) )


But now I found the culprit ... after starring another time at the lines ...

This line delivers ZERO:

h= sv4.Panel.width/2048*1536 (as does h= sv4.Panel.width/2048.0*1536.0 or h= sv4.Panel.width*1536.0/2048.0)

because sv4.panel.width is -1

When I force sv4.panel.width to 100%x it works. It seems the scrollview width is not properly set in the Addview routine.

Here is the working code

B4X:
        Case 3,4 'my photos
            sv4.Initialize(200%y)
            pan.AddView(sv4,0,0,Activity.Width,100%y-20dip) 'any width is ignored and sv4.panel.width is set to -1
            sv4.Panel.Width=100%x 'only this forces panel.width to be correct
            pan.Color = panelbkcolor
            sv4.Panel.Color = panelbkcolor
            Dim h As Int
            Log(sv4.Panel.Width)
            h=sv4.Panel.width*1536.0/2048.0 'was not relevant
            Log(h)
            pncam1.Initialize("")
            pncam1.Color=Colors.red
..and so on

Thanks again for taking care of your customers in such an excellent manner. I myself run a web based (hardware and software) customer activity and I know how difficult it is to do the right prioritization.

-- Andy
 
Upvote 0
Top