Android Question Separate layouts for different orientations ?

severika

Member
Licensed User
Longtime User
Hello,

I am trying make a GUI which looks nice on both orientations.

I created a layout "welcome_v" for vertical orientation and a layout "welcome_h" for horizontal.

I am switching between the two when I detect an orientation change, such as in Resume and Create methods, as following :

If Activity.Width > Activity.Height Then
Activity.LoadLayout("welcome_h")
Else
Activity.LoadLayout("welcome_v")
End If

It works fine so far.

I this a good practice ? Can you please recommend a better one ?
Thank you.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I this a good practice ?
No. You should instead use a single layout file with two variants. This way you will only need to modify the views position and size.

With that said, in many cases you can use a single variant and change the layout with anchors and designer script.
 
Upvote 0
Top