Android Question Scrollview panel height to match loaded layout

barx

Well-Known Member
Licensed User
Longtime User
Howdy chaps and chapettes.

I may be having a blonde moment here, but here goes. Simple version:

I have an activity and on the activity I have a scrollview (100%x x 100%y) this is just a container to enable the other views to scroll. In code I load a layout (we'll call it layout1.bal) into the inner panel of the scrollview. Now, how do I size the inner panel to match the loaded layout.

Only ways I can think of it to put a dummy view in the layout and put it right at the bottom of layout then in code reference that views' position. Or iterate through the views of the inner panel and check which is furthest down. I feel sure there must be an easier way, but not touched b4a in a good while and I appear to have lost my touch....

Thanks
 

stevel05

Expert
Licensed User
Longtime User
Try setting the inner panel height and width to -2, which is the value of the Constant WRAP_CONTENT.
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Using

B4X:
sv.Panel.Height = -2

creates a massive inner panel. I can scroll for ages and not get near the bottom.
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
the layouts are done in designer. ViewPager -> Scrollview -> Designer Layout
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Ah, sorry, misunderstood you. Here is the more precise version

array of pages to be built for viewpager
B4X:
Dim Pages() As String = Array As String("Site", "Strings", "Checks", "EIC", "Photos")

initializing pager

B4X:
    For i = 0 To Pages.Length -1
        PageContainer.AddPage(CreateLayout(Pages(i)), Pages(i))
    Next

As you can see, this calls the CreateLayout Sub
B4X:
Sub CreateLayout (Title As String) As ScrollView
    Dim sv As ScrollView
    Dim pnl As Panel
   
    pnl = CreatePanel(Title)
   
    jObj = pnl
   
    sv.Initialize((100%y - 40dip))
    sv.Panel.AddView(pnl, 0, 0, -2, -2)
    DoEvents
    Dim hi As Int = jObj.RunMethod("getHeight", Null) 'ignore this bit, trying to get height :P
    Log(hi)
    sv.Panel.Height = -2
    Return sv
End Sub

Again as you can see this calls the CreatePanel sub

B4X:
Sub CreatePanel(Title As String) As Panel
   Dim pnl As Panel
   
   pnl.Initialize("")
   Log(pnl.LoadLayout(Title.ToLowerCase))
   Return pnl
End Sub

The layouts are a mixture of all sorts, hence I need to detect height. one has a list of 9 button that are fine portrait, but go off bottom of screen landscape. another WILL have a long list of checkboxes with text descriptions that will definitely go off screen, another a mixture of edit text and labels......
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Kinda fixed it with a little iterator

I added this to the routine

B4X:
Dim Height As Int = 0
    For Each v As View In pnl.GetAllViewsRecursive
        If (v.Top + v.Height) > Height Then
            Height = (v.Top + v.Height)
        End If
    Next

Then set the height of inner panel to
B4X:
sv.panel.Height = Height + 20dip
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Wow, this is quite different from the first post ;) !
B4X:
Sub CreatePanel(Title AsString) As Panel
    Dim pnl AsPanel
    pnl.Initialize("")
    Log(pnl.LoadLayout(Title.ToLowerCase))
    Return pnl
End Sub
Log(pnl.LoadLayout(Title.ToLowerCase)) what is this ?
Do you load the layout or don't you !?
If no, where are they loaded ?

Then, once again I ask the same question, how are these layout files defined ?
I hope that all the view of these layouts are on a Panel.
So you might define an array, layoutPanelHeight(), with the Height of these Panels layoutPanelHeight() = layoutPanel.Height and set sv.Panel.Height = layoutPanelHeight(i).
 
Last edited:
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
I added the log to see the returned layout values to see if they where any use. I honestly don't understand what you mean by how are the layouts defined, I will post the project in a bit so you can see. I have only just started it.
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
project attached...
 

Attachments

  • project.zip
    16.3 KB · Views: 157
Upvote 0

klaus

Expert
Licensed User
Longtime User
Attached you find a partially modified version of your project.
To get the principle look at the photos layout file where I added a Panel and moved all views onto this Panel.
I didn't take the time to change all the other layout files.
But photos shows the principle.
 

Attachments

  • project_1.zip
    16.3 KB · Views: 187
Upvote 0
Top