Android Question Difference between CustomView with layout and CustomView with code

Filippo

Expert
Licensed User
Longtime User
Hi,

I have noticed a different behavior between a CustomView with a layout and one with code.
In my opinion this difference should not be, or what do you think?

For Label-CustomView with a layout, the log-output is = 0
For the Label-CustomView with code, the log-output is = 13
For the label standard, the log-output is = 15.86358642578125

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("frmMain")
    
    Log("fsLabelWithLayout1-TextSize=" & fsLabelWithLayout1.TextSize)
    Log("lblStandard-TextSize=" & lblStandard.TextSize)
    Log("fsLabelWithCode1-TextSize=" & fsLabelWithCode1.TextSize)
End Sub

Here is the log output:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
fsLabelWithLayout1-TextSize=0
lblStandard-TextSize=15.86358642578125
fsLabelWithCode1-TextSize=13
** Activity (main) Resume **
 

Attachments

  • Test3.zip
    11.4 KB · Views: 46

teddybear

Well-Known Member
Licensed User
Hi,

I have noticed a different behavior between a CustomView with a layout and one with code.
In my opinion this difference should not be, or what do you think?

For Label-CustomView with a layout, the log-output is = 0
For the Label-CustomView with code, the log-output is = 13
For the label standard, the log-output is = 15.86358642578125

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("frmMain")
 
    Log("fsLabelWithLayout1-TextSize=" & fsLabelWithLayout1.TextSize)
    Log("lblStandard-TextSize=" & lblStandard.TextSize)
    Log("fsLabelWithCode1-TextSize=" & fsLabelWithCode1.TextSize)
End Sub

Here is the log output:
They are no different.
That's because the Label Custom View with a layout loading layout was not completed, IsReady was false, the getTextSize returned 0 as default.
If you add a sleep before log or put log into button1_click event, it will work
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("frmMain")
    Sleep(0) 'Added sleep for waiting loadlayout completion'
    Log("fsLabelWithLayout1-TextSize=" & fsLabelWithLayout1.TextSize)
    Log("lblStandard-TextSize=" & lblStandard.TextSize)
    Log("fsLabelWithCode1-TextSize=" & fsLabelWithCode1.TextSize)
End Sub
 
Last edited:
Upvote 0

Filippo

Expert
Licensed User
Longtime User
If you add a sleep before log or put log into button1_click event, it will work
I have already noticed that too.

They are no different.
That's because the Label Custom View with a layout loading layout was not completed, IsReady was false, the getTextSize returned 0 as default.
If you add a sleep before log or put log into button1_click event, it will work
The difference is that with "Label a custom view with a layout" you need to add a "sleep(0)", and that's what makes the difference.
In my opinion, there should be no difference here.
 
Upvote 0
Top