Handling orientation changes

rfresh

Well-Known Member
Licensed User
Longtime User
Where is the tutorial on how to correctly handle orientation changes in your code? I've seen something on this but I can't remember where!!

Thanks...
 

nfordbscndrd

Well-Known Member
Licensed User
Longtime User
Where is the tutorial on how to correctly handle orientation changes in your code? I've seen something on this but I can't remember where!!

I'm not sure what you mean about "correctly handle orientation changes", but the simplest answer is that you create a layout for portrait orientation and one for landscape, then when the device changes orientation, Android loads the appropriate one.

If you are referring to the fact that when the device is rotated, your app restarts and the user loses his position in the app as well as any data, then see the first two subjects on this page in the Documentation Wiki.
 
Upvote 0

rfresh

Well-Known Member
Licensed User
Longtime User
I guess I've been reading so much info on B4A I'm a bit lost at this point regarding designing my Landscape layout and how the switching between the two is handled in my code.

My app has Activity.LoadLayout("Main") so this means that Main is my primary or main screen layout design right? It's portrait. But now I'm ready to design the landscape layout.

So in the Designer I would do File New and create a new Abstract Designer layout right? Normally what would you name this landscape layout? Main is the portrait layout so landscape would be??? I don't know if there is a naming convention here.

So I design my landscape layout and save this new layout and I know I can load it using the LoadLayout() function but where do I detect the orientation change in order to load the landscape layout? What Sub?

Thanks...
 
Upvote 0

rbsoft

Active Member
Licensed User
Longtime User
You can save more than one layout in one layout file. So you would simply save the landscape layout also to your main layout file. Like this you have portrait and landscape in the same layout file. Your program will automatically load the correct one.

Rolf
 
Upvote 0

JonPM

Well-Known Member
Licensed User
Longtime User
So I design my landscape layout and save this new layout and I know I can load it using the LoadLayout() function but where do I detect the orientation change in order to load the landscape layout? What Sub?

Thanks...

In Activity_Resume
 
Upvote 0

rfresh

Well-Known Member
Licensed User
Longtime User
You can save more than one layout in one layout file. So you would simply save the landscape layout also to your main layout file. Like this you have portrait and landscape in the same layout file. Your program will automatically load the correct one.

Rolf

So in the Abstract Designer, from the Layout menu, I would select my desired landscape mode and then setup my design in landscape. Then I'm still in 'Main' but now I have two layouts? I'm not clear on how 'to save the landscape layout' to my main layout file?

So in the attached image, I have opened a landscape layout and will position my components accordingly. But how do I save it when I'm done?

Sorry I'm not picking this up...I just can't wrap my head around this yet. I'm still trying to figure this out. Thanks.
 

Attachments

  • 0.jpg
    0.jpg
    71.4 KB · Views: 440
Last edited:
Upvote 0

rbsoft

Active Member
Licensed User
Longtime User
Exactly. In the designer just click on New Variant and add the desired landscape layout, adjust the views on it, and save the layout file.

Check in the Beginner's Guide v1.6. Go to page 103 (or chapter 8.7.2) There exactly this issue is described very detailed with lots of illustrations.

Rolf
 
Upvote 0
Top