Android Question [Solved] I cannot understand the way, different layouts work together

Pflichtfeld

Active Member
Licensed User
I cannot cope with this designers- and panel-transparency logic
I would expect such a screen:
test.png
But it never comes. The red panel does not appear, whatever I try.
Can anybody please explain me, what is wrong?
 

Attachments

  • test.zip
    9.7 KB · Views: 64

Pflichtfeld

Active Member
Licensed User
Thank you Klaus for your labour and effort! This helped me a lot to understand, together with the other answers.
Panel2, is a child of Panel1 and covers the bottom half part of the screen.
You set Panel2.SetTopAndBottom(50%y, 100%y), which is OK.
Panel2t, is a child of Panel2 with the same size. And you set it with:
Panel2t.SetTopAndBottom(50%y, 100%y), which is wrong !!!
Because the reference of the top coordinate of Panel2t is Panel2!!
It seems I got confused due to a posting of Erel where he writes:
25%x means a quarter of the activity width. Not the parent. There is one exception. %x / %y in the designer script are relative to the main parent which is the view that loads the layout.
From the different answers here I assume this must be wrong. % is always refering to the parent view. Even in designer.
Then why did you need to add a transparent panel Panel2t on top of Panel2 with the same dimensions? Without Panel2t, when you load L2, which has a transparent background it set the background of Panel2 to transparent. You set Panel2t to transparent, but the transparency of Panel2t at the end doesn't come from the background you set, but from the background of layout l2. Set the background of Panel2t to any non transparent value and it works the same.
It seems, that my device does not work in this manner: Even a transparent L2 does delete the view, it is loaded in, if this view is not set to transparent. I could solve this issue here with Erels help.
Do you really see the color of panel2t, if you set it to non-transparent? On my device it gets overwritten by L2 and I see panel2. If I delete panel2t, then panel2 is overwritten and not visible.
I would work with one Activity and Panels and show or hide the Panels depending on the different cases.
I considered that, but the code I use is huge, and I thought it would be clearer, if I spread it to different activities.
 
Upvote 0

Pflichtfeld

Active Member
Licensed User
No, he put Panel2t onto Panel2 because of the transparency!
At least, that is how I understood it, because he wrote somewhere that he had to add a transparent Panel to get his layout to work.
That is right. It was the only way i got it to work.
 
Upvote 0

klaus

Expert
Licensed User
From the different answers here I assume this must be wrong. % is always refering to the parent view. Even in designer.
No.
%x and %y refer to the parent view where you load the layout!
In your example:
You load layout L0 onto the Activity, so for ALL views in this layout %x and %y refer to the Activity.
You load layout L2 onto Panel2t, therefore Panel2t is now the reference, %y is equal to Panel2t.Height in this case.
But don't confuse with Top, Left etc. these properties refer to the top left corner of the parent view also in the Designer.

My phrase:
Then why did you need to add a transparent panel Panel2t on top of Panel2 with the same dimensions?
Was not right, it should have been:
Then the reason, why you did need to add a transparent panel Panel2t on top of Panel2 with the same dimensions is!
I updated it in my post

So I thought it to be a good idea, put the particular views in particular layouts and load in each activity the main-layout and then into a panel of layout main the particular layout.
Is the code for the common layout the same in all Activities?
I think you might consider Classes.
 
Upvote 0

Pflichtfeld

Active Member
Licensed User
The effect I wanted is (as you wrote in #9)
B4X:
Panel2t.SetTopAndBottom(0,Panel2.Height)
In my example the same is achieved with
B4X:
Panel2t.SetTopAndBottom(0%y,50%y)
what is really strange and leads me to this conclusion:
setTopAndBottom actually refers to the activity (as you allways sayed). Lets say: a size is produced, using activity-measures. But then this size is transferred into panel2.(and that all happens in designer). This is the only way all that makes sense for me.
So y%0 later refers to y0 in panel2 and SetTopAndBottom does not scale the view within panel2.

Ush, this was a hard nut to crack for me!
Thank you ALL, I hope it all works the way it appears to me now!!
 
Upvote 0

Erel

Administrator
Staff member
Licensed User
setTopAndBottom actually refers to the activity (as you allways sayed). Lets say: a size is produced, using activity-measures. But then this size is transferred into panel2.(and that all happens in designer). This is the only way all that makes sense for me.
You must be more accurate. SetTopAndBottom doesn't refer to anything.
Exactly as I previously wrote: %x and %y in the designer script are relative to the parent or activity that the layout is loaded to.
You should never ever use %x and %y to set the size or position of nested views. Only use them to set the layout of views added directly to the "activity" view in the layout.
 
Upvote 0
Top