iOS Question 100%x value before/after LoadLayout() which layout containing a panel

dersheng

New Member
Licensed User
I use B4i 4.30.
I create a layout file containing a panel and a button.
After LoadLayout() is called, I use log() to print out 100%x, 100%y values.
Then I click the button, in the button Click event function, print out the 100%x, 100%y values again.
But the new 100%x, 100%y values are different from the old values before clicking the button.

The new 100%x, 100%y are closed to the panel size.
I have no such problem in B4A.

Please answer my question, thanks!
 

dersheng

New Member
Licensed User
My log is shown as
===
Copying updated assets files (1)
Application_Start
(1) 100%x=320, 100%y=568
(2) 100%x=320, 100%y=504
Application_Active
In Button1_Click()
Panel1, width=199.3016, height=199.3016
(3) 100%x=199.3016, 100%y=199.3016
===========
The attached is my project file.

Please help me.
 

Attachments

  • B4i_ex1.zip
    2.1 KB · Views: 250
Upvote 0

sorex

Expert
Licensed User
Longtime User
you need to load or create your views in the page resize sub

B4X:
Private Sub Page1_Resize(Width As Int, Height As Int)
Page1.RootPanel.LoadLayout("Form1")
Log("(2) 100%x="&100%x&", 100%y="&100%y)
End Sub

I know it's confusing because only 1 of my 8 apps had this weird behaviour and needed the init in the resize sub to work right.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User

this is not correct.

if you load every time in resize event your layout you may have multiple views in your app.
resize event will run in many cases like rotating the phone, changing from landscape to portrait because of an incoming call...

you should load your layout in Application_Start event and then handle the resize in resize_event or from the designer.

to get the size of the activity you should do it after resize_event was raised.
as erel said its better to use the page1.rootpanel.width/height for this.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
I use forced portrait or landscape modes and then I think the resize only kicks in only once even when leaving the app to a 'rotated mode' and getting back.

I'll need to verify this tho but I never saw my app restart by switching apps.

For protrait/landscape responsive designs you're right for sure.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User

start your app and have it on foreground, then perform a call to your phone from another phone and you will see that the resize event will be called again.
its better to have a global variable that will tell you that the resize event was raised and you can ask for it before you perform any resizing in your resize event.
 
Last edited:
Upvote 0

sorex

Expert
Licensed User
Longtime User
unfortunately I don't use any of the iPhones as phone.

so I can only rely on manually switching apps and there I only see in the log...

Application_Start
Application_Active
Application_Inactive
Application_Background
Application_Foreground
Application_Active
Application_Inactive
Application_Background
Application_Foreground
Application_Active
Application_Inactive
Application_Active

no output of the log("resize") I've put in the resize sub.

I tried using an alarm but that just gave an overlayed msgbox and not a page switch.
Any other trick to let another app kick in?
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
i had the problem that my app was every time resized when an incoming call happened and the app was in foreground.
it happened to one of my users and he reported that everything is very small on the screen and i could not understand what he means.
then he told me that it not happens every time he enters the app. after some investigation i found out that an incoming call will call the resize event.

so i had to put a global variable to ensure that the resize event will only be called once.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…