Android Question Catch-22 with Panels and LoadLayout.

Tom_707

Member
Licensed User
When creating a Panel in code, I need to define its size to match the dimensions of the layout which will be loaded into it using the LoadLayout method.
If the size of the Panel is not correct, the layout won't display properly. But the dimensions of the layout are only available once it has been loaded.

Is there a method or some way to access a layout's dimensions before the LoadLayout method is called?
If this is not possible, what is the best way to create the correct Panel size to match the layout?
(I have multiple layouts and the one that will be loaded is only known at runtime).
 

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
The way I would do this is to have a panel,p1, on the layout which is the size required, this panel will have no constraints. (this would generally be the background of the layout)

then
B4X:
Private p2 As B4XView

p2 = xui.createpanel("p2")

p2.LoadLayout("layout")

p2.width = p1.width
p2.Height = p1.Height
 
Upvote 0

Tom_707

Member
Licensed User
This is exactly what I don't want.

I would like:
B4X:
Private bxvPanel As B4XView

bxvPanel.Width = x dip
bxvPanel.Height = y dip

bxvPanel.LoadLayout("layout")

Where x and y are the dimensions of the layout. I would like to know these dimensions before LoadLayout is called.
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
As the Rolling Stones said "You can't always get what you want". :)

The proposed solution will work. As you suggest it is not possible to get the size of a layout before loading it. As such I was answering the second question.
If this is not possible, what is the best way to create the correct Panel size to match the layout?
 
Upvote 0

Tom_707

Member
Licensed User
If I wanted a quote from the Rolling Stones, I would have gone to a music forum.
If you can't provide a good solution to the problem, then why are you replying to my post?
 
Upvote 0

Tom_707

Member
Licensed User
There is no such thing.
It is always the "container" that defines the dimension for the child layout.

Hi Erel,

I was trying to simplify the question, but it looks like I oversimplified it.
What I meant to ask was:
I have a View in a layout, and I want to load this layout into a Panel I created in code.
How can I determine the size of this View so that I can define the correct dimensions for the Panel in code, before calling the LoadLayout method.
 
Upvote 0

Tom_707

Member
Licensed User
I understood it and the answer is: there is no such thing. Layouts do not have an intrinsic dimension. It is always the container that sets the size for the child layout.

You should use anchors and designer script to make the layout as flexible as possible and then set the container size to be whatever you need.
OK, I get it now.
Thanks Erel.
 
Upvote 0
Top