B4J Question [B4XPages] How can I move a label in a panel in Root in a B4XPage?

William Lancee

Well-Known Member
Licensed User
Longtime User
Under certain conditions I want to move a label down a bit in B4XPage_Created. The label is defined in designer layout.
It works when I load the layout in Root of the B4XPage.
But when I have a panel in Root and load the layout into the panel...
it appears to adjust the top of label, but when the page is shown and appears, the top is back to the designer specified top.

What am I missing? See super small example attached (B4Pages: B4J)
 

Attachments

  • testMove.zip
    10.2 KB · Views: 78
Solution
Have you tried unchecking the "Handle Resize Event" box?

1691777743340.png

Daestrum

Expert
Licensed User
Longtime User
I could only get it to move by using a translateY on it, changing top had no effect.
SetLayoutAnimated can also move it.
 
Last edited:
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
@Daestrum

Thanks for looking at this.

I tried SetLayoutAnimated on the B4XView caste of Label1, but that didn't work.
What did you try?

I am not familiar with translateY. Is that a Java object thing?

What is funny is that the .top=200 works when the label is not in a panel.
 
Upvote 0

PaulMeuris

Active Member
Licensed User
The B4XPage_created from the tm page:
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Log("layout prepared...")
'As label in root
'    Root.LoadLayout("justLabel")
    
'As label in panel in root   
    Dim pnl As B4XView = xui.CreatePanel("")
    pnl.LoadLayout("justLabel")
    Root.AddView(pnl, 0, 0, Root.Width, Root.Height)

    Sleep(0)
    Label1.Top = 200
End Sub

Private Sub B4XPage_Appear
    Label1.SetLayoutAnimated(0,100,150,Label1.PrefWidth,Label1.PrefHeight)
    Log("moved to: " & Label1.Left & " " &  Label1.top)
End Sub

The layout from the tm page is already prepared before you click on the button in the B4XMainPage as you can see in the logs.
Waiting for debugger to connect...
Program started.
*** mainpage: B4XPage_Created
*** tm: B4XPage_Created
layout prepared...
*** mainpage: B4XPage_Appear
*** mainpage: B4XPage_Resize [mainpage]
*** tm: B4XPage_Resize [mainpage]
200
*** tm: B4XPage_Appear [mainpage]
10
moved to: 100 150
*** tm: B4XPage_Disappear [tm, mainpage]
*** mainpage: B4XPage_Disappear [mainpage]
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
@aeric
That was my work-around. However, in my situation that caused a brief but noticeable movement on the screen.
Only the first time, subsequent shows didn't need it anymore.

@PaulMeuris
Yes the B4XCreated has started and finished before I press the button.
That is why it is so puzzling why the ShowPage seems to revert it back to the layout top.
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
@aeric
Thanks for looking at this.
That was only done in the example to show the problem. In the actual app it was done with the designer.
I reduced the app to bare essentials.

However, mentioning the Designer made me think of the Designer Script Extensions. Doing the move there
solves the problem - but not the puzzle.
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
Hi there... (missed all of you... work in shop not stops... and no time for anything)

I think the whole thing... that label is layout loaded into a panel... how about adding an extra panel into the panel...
or moving the panel and not the label... it seems working... (moving the panel)
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
How I am reading that:

B4X:
    Dim pnl As B4XView = xui.CreatePanel("")  'create a panel as b4xview ok - acceptable...
    pnl.LoadLayout("justLabel")    'replace my panel-b4xview with the layout of "justlabel" file
    Root.AddView .... 'now please show and move it at specific position with width and height set it like the root
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
@Magma
panel and not the label... it seems working... (moving the panel)
Yes that works the same way as loading the label layout directly into Root.

#10
It doesn't make any difference whether the layout is loaded before or after the pnl is added to the Root.
(it would if anchors where 'filling')

#11
Tried the attached. No difference whether Sleep(0) or Sleep(1111).

Also note that the Log prior to the call to ShowPage proves that the move was made.
Somehow the ShowPage reverts the layout back to the original position prior to the move. That's what's puzzling.

However, since the DSE approach does work, I'll accept that there will be always mysteries I don't understand.
Thanks to all who looked at this.
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
#11 For me had difference... maybe need to add more time.... let's say 5000ms.. you will see it move (not returning at start position)

May be it has to do with "Time of B4X works" and multitasking/multithreading (better)... It has the timing it wants the right Time that believes :) ..

For example adding an extra button to Mainpage layout... and clicking after a while clicking button1... works well...

B4X:
Private Sub Button2_Click
    tm.Label1.Top=-100
End Sub
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
@teddybear
Thank you for that reference. I suspected it was something related to resize.
This is a situation where searching for solutions to my problem would not find that post.
I don't know how one would find that without the collective memory of the Forum.

I also did not know about

B4X:
    XUIViewsUtils.CreateLabel
    XUIViewsUtils.CreateB4XImageView
 
Upvote 0
Top