Android Question Loading different layouts on on same activity

walterf25

Expert
Licensed User
Longtime User
Hello all, i came across a very confusing issue and was wondering if maybe there's something i've missed during the last 3 o or 4 updates of B4A.

So, I have one activity and i have 2 different panels, the first panel starts at the top of the activity and the height is around 45% of the total height of the activity, the tablet i'am using has a resolution of 800x1280, the second panel starts at the bottom of the first panel and its height is also around 45% of the activity's total height.

I want each panel to load a different layout, the layouts i have created them using the designer. Each layout only contains around 10 to 11 labels and edittext boxes.

The issue i'm seeing is that both panels were loading each of the layouts just fine, and suddenly i noticed that the first panel doesn't load its layout anymore, however the second panel load its layout just fine.

My question is this: is it not possible to have more than one panel in one activity and have each panel load different layouts at the same time?

This is giving me a headache :mad::mad:
I don't see why this wouldn't be possible!

Here's what i've tried so far:
I copied all the views on the first layout and created a whole new layout and pasted those views onto the new layout, the first time i run the project i saw the first layout loaded just fine, the second time the same problem, the layout did not show up, so basically i see a big empty white space starting from the top down to about 45%y. and the panel with the second layout shows just fine below where the first panel with the first layout should show up.

I then deleted the parent panel and placed all the views on the layout without any parent panel.

I have a panel on the top as a header and inside the panel i have a label, I run the project and it loads the layout fine with all the labels and the edittext boxes but the header panel with the label inside of it, does not show up.

WTH.

I've put together a sketch of what i'm trying to do, as you can see there are two different panels where each panel should load a different layout.

and here's also the code.

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
sv.Initialize(10000)
Activity.AddView(sv, 0, 0, 100%x, 100%y)
parentpanel.Initialize("parent")
parentpanel2.Initialize("parent2")
parentpanel.LoadLayout("gnrldetails")
parentpanel2.LoadLayout("hdrportcalls")
sv.Panel.AddView(parentpanel, 0, 0, 100%x, 80%y)
sv.Panel.AddView(parentpanel2, 0, (parentpanel.Top + parentpanel.Height) - pnlsection.Height, 100%x, 30%y)
End Sub

MAIN_ACTIVITY.png

I totally feel like a newbie, i can't see why this is happening.

Some help please?

EDITED:
Added a small project to show the problem.


Thanks,
Walter
 

Attachments

  • problem_Example.zip
    11 KB · Views: 182
Last edited:

eurojam

Well-Known Member
Licensed User
Longtime User
Hi Walter,
I've tried your code with two basic layouts, no problems. find attached the sample.

stefan
 

Attachments

  • test.zip
    8.9 KB · Views: 181
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
There has not been any change. I have tested above and am able to display both layouts ..
I cant think what might be causing this , apart from the obvious .. parentpanel1 not visible etc.

Maybe try new dummy layout in first panel ?

I did try to load the same layout twice to the two individual panels .. but that threw error which surprised me.
But thats question for another day.
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
There has not been any change. I have tested above and am able to display both layouts ..
I cant think what might be causing this , apart from the obvious .. parentpanel1 not visible etc.

Maybe try new dummy layout in first panel ?

I did try to load the same layout twice to the two individual panels .. but that threw error which surprised me.
But thats question for another day.
That is so odd, i tried it on the my Samsung Tab 7 and my LG G3 as well, and on both i see the same issue, i only see the second layout.

Bummer :mad:
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
That is so odd, i tried it on the my Samsung Tab 7 and my LG G3 as well, and on both i see the same issue, i only see the second layout.

Its got to be something simple .. its moments like this I go back to basics. Two new layouts & big, bright, colored panels. sharing screen 50% each.

OR load the missing layout direct to activity .. and rem loading the SV
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Its got to be something simple .. its moments like this I go back to basics. Two new layouts & big, bright, colored panels. sharing screen 50% each.

OR load the missing layout direct to activity .. and rem loading the SV
I've already tried all those things, loading the missing layout only but it still doesn't show up, i can tell the pnlparent is loading because i see the empty blank space and it's height it's equivalent to what i specify in my code.

I've also tried pnlparent.bringtofront and pnlparent.visible = True
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
I've already tried all those things, loading the missing layout only but it still doesn't show up, i can tell the pnlparent is loading because i see the empty blank space and it's height it's equivalent to what i specify in my code.

I've also tried pnlparent.bringtofront and pnlparent.visible = True

upload the project if you want ..
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
upload the project if you want ..
I've already uploaded a project on the first post those are the same layouts i use in the actual project.
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
I've already uploaded a project on the first post those are the same layouts i use in the actual project.
Yes .. agree the first layout is not visible .. ? will come back.
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Yes .. agree the first layout is not visible .. ? will come back.
Oh that's great that you see the issue for a moment there i thought i was going crazy lol.
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
Oh that's great that you see the issue for a moment there i thought i was going crazy lol.

Sorry .. did not see the uploaded project post#1. the original test I used post code.

Unless someone has alternative .. the only way I could get this to work was completely deleting 'hdrdetails' layout , and loading new one.
I tried copies , removing views etc .. even back to empty layout.
The layout must be corrupt in some way
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Sorry .. did not see the uploaded project post#1. the original test I used post code.

Unless someone has alternative .. the only way I could get this to work was completely deleting 'hdrdetails' layout , and loading new one.
I tried copies , removing views etc .. even back to empty layout.
The layout must be corrupt in some way
I tried new layout as well, and it works fine the first or second time, but then the layout just disappears again.
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
I tried new layout as well, and it works fine the first or second time, but then the layout just disappears again.
Sorry not getting that . Deleted 'hdrdetails'. Whipped up new replacement layout and it loads every time exactly as it should... debug and release.
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Sorry not getting that . Deleted 'hdrdetails'. Whipped up new replacement layout and it loads every time exactly as it should... debug and release.
Ok, i think i may have found the problem, don't know what causes it or why it does it, I think it might be a bug with the designer, i can't think of any other explanation.

So the first thing I did was on the first layout, hdrdetails, on the pnlheader view and on the horizontal anchor property i had it set to "BOTH" on both layouts, i changed that property to "LEFT" and run the project, the first layout showed up, but the second one didn't, so i then went to the second layout hrdportcalls and changed the pnlheader2 horizontal anchor property to "LEFT" as well then run the project and both layout showed up, If i go back to the first layout and change the horizontal anchor property to "BOTH" then i see the same issue all over again, as I mentioned above, this seems like a bug with the designer, i really can't think of any other explanation. Another thing i noticed and forgot to mention earlier is that the label on the pnheader2 view on the second layout, was not showing up centered, even though i had the horizontal anchor property set to "BOTH" and the horizontal alignment set to CENTER as well, once i decreased the width of the pnlcontainer2 by about 5%x then the label now shows up CENTER aligned.

i'm telling you, something is up with the designer.

Anyhow thank you all for your time, i'd like to hear if anyone else comes across this or any other similar issue.

Thanks
Walter
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
Ok, i think i may have found the problem, don't know what causes it or why it does it, I think it might be a bug with the designer, i can't think of any other explanation.

just to confirm .. I only changed the horizontal anchor of 'parentpanel' to 'Left' and all was good. the 1st layout displayed correctly.
changing it back to 'Both' resulted in layout not showing.

Changing anchors on 'parentpanel2' had no effect

I did notice you were also getting logs .. "Panel size is unknown. Layout may not be loaded correctly."
Maybe read Here ...
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
just to confirm .. I only changed the horizontal anchor of 'parentpanel' to 'Left' and all was good. the 1st layout displayed correctly.
changing it back to 'Both' resulted in layout not showing.

Changing anchors on 'parentpanel2' had no effect

I did notice you were also getting logs .. "Panel size is unknown. Layout may not be loaded correctly."
Maybe read Here ...
So you did see the problem, i'm not getting any logs on my side, what i noticed is that pnlheader and pnlcontainer can not both have the horizontal anchor parameter set to BOTH at the same time, so what I did is i've set the horizontal anchor parameter on the pnlcontainer to LEFT and pnlheader to BOTH, this fixes that issue, if i set both panels to BOTH on the horizontal anchor parameter then the issue persists, it still doesn't make any sense why this is though? I wish Erel would have some time to look into this, or maybe he already has an explanation for this issue.

Cheers,
Walter
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Sorry, but I don't uderstand what exactly you want to do.
So, I have one activity and i have 2 different panels, the first panel starts at the top of the activity and the height is around 45% of the total height of the activity, the tablet i'am using has a resolution of 800x1280, the second panel starts at the bottom of the first panel and its height is also around 45% of the activity's total height.
You say :
- That the first panel starts at the top of the activity, but in the code you add it onto a ScrollView.Pabel !?
- That the first panel has a height of 45% of the screen height, but in the code you add the parentPanel with 80%y !?
sv.Panel.AddView(parentpanel, 0, 0, 100%x, 80%y)

In your layout file you use a very special varaiant 800 * 1280 scale 1.33215
You should never use a scale different from 1 in layouts !

In the hdrdetail variant you use two times:
AutoScaleRate(0.2)
AutoScaleAll
One time in the Script-General and a second time in the Script-Variant !?
It must be called only once!

You use an AutoScaleRate of 0.2, this will not work whan you downscale.

In some layouts you have views overlapping, is this really what you want ?


It would be better to use a 'standard' layout variant 320 * and upscale.

You dont need to use the two parentpanels. As your two layouts are aleady on panels you can download the two layouts directly onto the ScrollView.Panel and position the top of the second panel according to the height of the first one. And then set the height of the ScrollView.Panel equal to the sum of the heights of the two panels.

Attached your project modified.
I load the layouts like above, I commented all AutoScale commands for testing.
I didn't make the standard layout variants.
 

Attachments

  • problem_Example_1.zip
    10.9 KB · Views: 178
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Sorry, but I don't uderstand what exactly you want to do.

You say :
- That the first panel starts at the top of the activity, but in the code you add it onto a ScrollView.Pabel !?
- That the first panel has a height of 45% of the screen height, but in the code you add the parentPanel with 80%y !?
sv.Panel.AddView(parentpanel, 0, 0, 100%x, 80%y)

In your layout file you use a very special varaiant 800 * 1280 scale 1.33215
You should never use a scale different from 1 in layouts !

In the hdrdetail variant you use two times:
AutoScaleRate(0.2)
AutoScaleAll
One time in the Script-General and a second time in the Script-Variant !?
It must be called only once!

You use an AutoScaleRate of 0.2, this will not work whan you downscale.

In some layouts you have views overlapping, is this really what you want ?


It would be better to use a 'standard' layout variant 320 * and upscale.

You dont need to use the two parentpanels. As your two layouts are aleady on panels you can download the two layouts directly onto the ScrollView.Panel and position the top of the second panel according to the height of the first one. And then set the height of the ScrollView.Panel equal to the sum of the heights of the two panels.

Attached your project modified.
I load the layouts like above, I commented all AutoScale commands for testing.
I didn't make the standard layout variants.


Hi Klaus thank you for taking the time to look at this post.

You say :
- That the first panel starts at the top of the activity, but in the code you add it onto a ScrollView.Pabel !?
- That the first panel has a height of 45% of the screen height, but in the code you add the parentPanel with 80%y !?
sv.Panel.AddView(parentpanel, 0, 0, 100%x, 80%y)

you are right, this was my mistake, in my actual code the actual height of the parentpanel is only 45%y.

In your layout file you use a very special varaiant 800 * 1280 scale 1.33215
You should never use a scale different from 1 in layouts !

The reason i decided to use this variant is because this app will be only specific for the Samsung SM-T360 tablets, but i understand that i shouldn't use a scale different then 1, so i have changed the scale to 1.

In the hdrdetail variant you use two times:
AutoScaleRate(0.2)
AutoScaleAll
One time in the Script-General and a second time in the Script-Variant !?
It must be called only once!

Once again you are right, i have deleted the code from the Script-General part.

In some layouts you have views overlapping, is this really what you want ?
Yes, i've intentionally overlapped some views, since the aligment of the labels is "LEFT" and the text on the labels is really short, the gap between the label and the view to the right of label looks a little too much, so i've overlapped the views so that there will be very little space between the two views.

You dont need to use the two parentpanels. As your two layouts are aleady on panels you can download the two layouts directly onto the ScrollView.Panel and position the top of the second panel according to the height of the first one. And then set the height of the ScrollView.Panel equal to the sum of the heights of the two panels.

I realize i don't need two parentpanels, but nevertheless the issue which is the reason why i created this post shouldn't exist, i still think there's a bug in the designer.
I still don't understand why is it that, if i have for example one parent panel, and a headerpanel inside the parent panel, and if i set the Horizontal Anchor property of both panels to "BOTH", then the layout will not show up when i load it from the activity, But if i set the horizontal anchor property to "LEFT" on the parent panel and the horizontal anchor property to "BOTH" on the header panel then the layout will show up just fine.

I've already tried this issue on different devices and i get the same results if you do what i just described above.

By the way I'am using B4A version 5.5

Again thanks for your time and help with this Kraus.

Walter
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I realize i don't need two parentpanels, but nevertheless the issue which is the reason why i created this post shouldn't exist, i still think there's a bug in the designer.
The problem is that you load the layouts onto the parent panels before you add the parent panels onto the scrollview.
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    sv.Initialize(10000)
    Activity.AddView(sv, 0, 0, 100%x, 100%y)
    parentpanel.Initialize("parent")
    parentpanel2.Initialize("parent2")
    parentpanel.LoadLayout("hdrdetails")
    sv.Panel.AddView(parentpanel, 0, 0, 100%x, 80%y)
    parentpanel2.LoadLayout("hdrportcalls")
    sv.Panel.AddView(parentpanel2, 0, (parentpanel.Top + parentpanel.Height) - pnlheader1.Height, 100%x, 30%y)

    If tgladvnotrcvd.Checked = False Then
        tgladvnotrcvd.Color = Colors.LightGray
        tgladvnotrcvd.TextOff = ""
    End If
End Sub
You must load the layouts afterwards!
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    sv.Initialize(10000)
    Activity.AddView(sv, 0, 0, 100%x, 100%y)
    parentpanel.Initialize("parent")
    parentpanel2.Initialize("parent2")
'    parentpanel.LoadLayout("hdrdetails")
    sv.Panel.AddView(parentpanel, 0, 0, 100%x, 80%y)
    parentpanel.LoadLayout("hdrdetails")
'    parentpanel2.LoadLayout("hdrportcalls")
    sv.Panel.AddView(parentpanel2, 0, (parentpanel.Top + parentpanel.Height) - pnlheader1.Height, 100%x, 30%y)
    parentpanel2.LoadLayout("hdrportcalls")

    If tgladvnotrcvd.Checked = False Then
        tgladvnotrcvd.Color = Colors.LightGray
        tgladvnotrcvd.TextOff = ""
    End If
End Sub

Why do you subtract pnlheader1.Height when you add parentpanel2?
pnlheader1 belongs to pnlcontainer so no need to subtract its height.

By the way I'am using B4A version 5.5
Me too, I checked it before doing any test.
 
Last edited:
Upvote 0
Top