Designer Script Problem in B4a 2.71

mjtaryan

Active Member
Licensed User
Longtime User
I have an app under development and am working on the layout for the first (Main) Acitivity.

The code that is giving problems is "btnChkPicks.Top = lblPicked.Top".

B4X:
'Set Game Item Pick label.
lblPicked.Width = 22%x
lblPicked.HorizontalCenter = 50%x
lblPicked.Height = pnlGame.Height * .47
lblPicked.VerticalCenter = 27%y
'Set Buttons
'Set Show Picks button.
btnChkPicks.Top = lblPicked.Top 'This line not working correctly.
btnChkPicks.Width = lblPicked.Left * .50
btnChkPicks.HorizontalCenter = lblPicked.Left * .50
btnChkPicks.Bottom = lblPicked.Height - (btnChkPicks.Top - lblPicked.Top)

However, the tops of the lblPicked and btnChkPicks do not line up. The Log shows:

lblPicked.Top = 31
btnChkPicks.Top = 6

I can't see what I am doing wrong.

Also, should not the %x and %y values of an object be relative to the object's parent (the paent of both the obove objects is a panel)?

Thanks.
 
Last edited:

mistermentality

Active Member
Licensed User
Longtime User
I have an app under development and am working on the layout for the first (Main) Acitivity.

The code that is giving problems is "btnChkPicks.Top = lblPicked.Top".

B4X:
'Set Game Item Pick label.
lblPicked.Width = 22%x
lblPicked.HorizontalCenter = 50%x
lblPicked.Height = pnlGame.Height * .47
lblPicked.VerticalCenter = 27%y
'Set Buttons
'Set Show Picks button.
btnChkPicks.Top = lblPicked.Top 'This line not working correctly.
btnChkPicks.Width = lblPicked.Left * .50
btnChkPicks.HorizontalCenter = lblPicked.Left * .50
btnChkPicks.Bottom = lblPicked.Height - (btnChkPicks.Top - lblPicked.Top)

However, the tops of the lblPicked and btnChkPicks do not line up. The Log shows:

lblPicked.Top = 31
btnChkPicks.Top = 6

I can't see what I am doing wrong.

Also, should not the %x and %y values of an object be relative to the object's parent (the paent of both the obove objects is a panel)?

Thanks.

It might be because after you set chkPicks top position you then also set its bottom position as well. Have you tried commenting out the second from last line, the one where you change the chkPicks bottom position, to see if it is that?

If the intent of that line is to adjust the height of the button by adjusting the bottom position I think you can do that using .height.

Dave

Sent from my Nexus 7
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
You say this line is not working correctly.
btnChkPicks.Top = lblPicked.Top

For me, the problem is here:
lblPicked.VerticalCenter = 27%y
This sets the Top property to 27%y - lblPicked.Height / 2

And in fact it's 27%y - pnlGame.Height * .47 / 2
Is this what you expect ?
It seems to be no.

Where did you get these values ?
lblPicked.Top = 31
btnChkPicks.Top = 6



And as mistermentality already reported I'm not sure that this line is what you want.
btnChkPicks.Bottom = lblPicked.Height - (btnChkPicks.Top - lblPicked.Top)

Best regards.
 
Last edited:
Upvote 0

mjtaryan

Active Member
Licensed User
Longtime User
You say this line is not working correctly.
btnChkPicks.Top = lblPicked.Top

For me, the problem is here:
lblPicked.VerticalCenter = 27%y
This sets the Top property to 27%y - lblPicked.Height / 2

And in fact it's 27%y - pnlGame.Height * .47 / 2
Is this what you expect ?
It seems to be no.

Where did you get these values ?
lblPicked.Top = 31
btnChkPicks.Top = 6



And as mistermentality already reported I'm not sure that this line is what you want.
btnChkPicks.Bottom = lblPicked.Height - (btnChkPicks.Top - lblPicked.Top)

Best regards.

Thanks to you both.

Klaus, I must have forgotten to comment out or delete some of the lines you mention.

However, I tried another approach that worked as I wanted. So, the first part of my request is solved. I wasn't able to get back here to update this before getting the responses from the two of you. Sorry.

Nevertheless, my second question remains because I get some strange results when I attempt to use %x and %y with objects on a panel, particularly when there are two or more panels. For example a label1.Top = 3%y should be 3% of the height of the parent regardless of whether the parent is an activity or a panel. And, if a panel, shouldn't the top of label1 be relative to the top of the panel?

Thanks.
 
Upvote 0

mjtaryan

Active Member
Licensed User
Longtime User
Erel, s
Thanks Erel, that clarifies things and explains why objects weren,' t positining where I expected. Are %x and %y part of Android or B4a. If the latter, it wuld make it simpler more direct) if they were reative to their parento dees that mean I wuld have to load a layout for each panel I use?

Are %x, %y a feature of Android or B4a? If the latter, it seems it would be simpler and more direct if they were relative to an object's parent (I.e. Activity, panel, scrollview.panel , etc.). Yur reply explains why objects weren't always positined where I expected. Thanks.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The percentage feature is a Basic4android feature.

Do note that you can create a layout file and then load it to the panel. This way they will be relative to the panel.

It is not a clear cut. There are advantages (and technical reasons) for having it relate to a "global" value. Anyway it is not something that can be changed as it will break existing code.
 
Upvote 0

mjtaryan

Active Member
Licensed User
Longtime User
Erel;1762ll9 said:
The percentage feature is a Basic4android feature.

Do note that you can create a layout file and then load it to the panel. This way they will be relative to the panel.

It is not a clear cut. There are advantages (and technical reasons) for having it relate to a "global" value. Anyway it is not something that can be changed as it will break existing code.

Thanks Ere, I fully understand and had similar restrictions with systems I worked on. It was merely that in other environments I've used an almist identical feature was relative to the parent and I assumed wrongly B4a did the same. Thanks again.
 
Last edited:
Upvote 0

mjtaryan

Active Member
Licensed User
Longtime User
I have tried to create a layout file for a panel but am still having a problem.

1. The Activity has a main Panel (call it PanelA).
2. PanelA has a child panel (PanelA_1).
3. PanelA_1 is a number pad and, obviously, has buttons as children.
4. Activity.LoadLayout("pA") is executed in Activity_Create.
5. PanelA_1 is declared in Sub Globals.
6. In Sub Init (called from Activity_Create) PanelA_1 is initialized and then removed from the Activity (its parent).
7. PanelA_1 is then added to PanelA so that PanelA becomes the parent for PanelA_1.
8. PanelA_1.LoadLayout(pA1) is then executed.

In the Designer, the child buttons for PanelA_1 appear as expected in the Abstract Designer window when the script is run. However, when the app is tested, although PanelA_1 appears properly in PanelA, the children for PanelA_1 are not visible. What am I doing wrong? Thanks.
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
Sorry, but I don't really understand what you are trying to do.
Couldn't you post your project as a zip file so we could test it.
I don't understand why you need to remove PanelA_1 from the Activity to add it then to PanelA !
But without seeing the code it's mpossible to guess what you are doing.

Best regards.
 
Upvote 0

mjtaryan

Active Member
Licensed User
Longtime User
Sorry, but I don't really understand what you are trying to do.
Couldn't you post your project as a zip file so we could test it.
I don't understand why you need to remove PanelA_1 from the Activity to add it then to PanelA !
But without seeing the code it's mpossible to guess what you are doing.

Best regards.

First, when I tried to add PanelA_1 to PanelA I got an error saying PanelA_1 needed to be initialized. After I did that, I got another error saying it needed to be removed from its current parent.

I've attached a simpler, but similar project that also doesn't work as I'd hoped. It is is merely a test project. Please read the comment lines I've added. Thanks for the help.
 

Attachments

  • MultiLayouts.zip
    5.1 KB · Views: 159
Upvote 0

Theera

Expert
Licensed User
Longtime User
Hi mjtaryan,

Please see this,I think that it's easy way to manage the multi User Interface.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Attached you find a modified version.
- In the layout testB you must set Activity as the parent view of lblB and btnB and change Activity color tp the color of pnlB.
- You must remove pnlB from layout testB and add it testA onto pnlA !
That way pnlB is directly a child view of pnlA.
- Then you load testB onto pnlB like in your original code.

What is the difference.
- pnlB is directly a child view of pnlA
- As the layout testB is loaded onto pnlB, in the DesignerScript 100%x and 100%y refer now to the width and height of pnlB and not to the width and height of the Activity.

Best regards.
 

Attachments

  • MultiLayouts1.zip
    9.5 KB · Views: 146
Upvote 0

mjtaryan

Active Member
Licensed User
Longtime User
Attached you find a modified version.
- In the layout testB you must set Activity as the parent view of lblB and btnB and change Activity color tp the color of pnlB.
- You must remove pnlB from layout testB and add it testA onto pnlA !
That way pnlB is directly a child view of pnlA.
- Then you load testB onto pnlB like in your original code.

What is the difference.
- pnlB is directly a child view of pnlA
- As the layout testB is loaded onto pnlB, in the DesignerScript 100%x and 100%y refer now to the width and height of pnlB and not to the width and height of the Activity.

Best regards.

Thanks Klaus, but I'm still confused.

If the parent for lblB and btnB is changed from pnlB to Activity how do they become children of pnlB for layout purposes? Or does pnlB become the "Activity" because it loads the layout file? Thanks again.

UPDATE:


By Jove, I think I've got it!!

Klaus,

I ran and examined your modified version and then tried modifying the actual project I'm working on that was causing my consternation. Except for some minor spacing problems and the buttons being too dark, it works great.

And to boot, I now see how B4a does this. It is actually not that different from other systems I've used, just a slightly less direct method of achieving the same effect.

Thanks for your help and your time.
 
Last edited:
Upvote 0

mjtaryan

Active Member
Licensed User
Longtime User
Hi mjtaryan,

Please see this,I think that it's easy way to manage the multi User Interface.

Thanks, but this is not a multiuser problem. Rather it was a problem understanding how B4a (specifically) relates different containers and the layout files each of them loads.
 
Upvote 0
Top