Android Question Not using correct Layout

MrKim

Well-Known Member
Licensed User
Longtime User
sigh, I wish I understood this layout stuff. It baffles me.

I have 4 variants in my layout 1280X800, 800x1280, 900x600 and 600x900. All Scale = 1. Works fine on tablets.

I have a galaxy S7 edge phone. The resolution is, I am told, 2560x1440. Either of the portrait mode layouts would be fine in portrait mode.

The problem is it chooses A landscape layout regardless of the phone orientation. It would seem to me that, first and foremost layout would be chosen based on aspect ratio.

What I would really like is on small screens (read phones) the app would only work in portrait mode.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
2560x1440
There is no meaning to this value without the scale.
The problem is it chooses A landscape layout regardless of the phone orientation.
The orientation is considered when it looks for the best fit.

I agree with @NJDude that you should use as few as possible variants. Anchors and designer scripts are easier to work with.
 
Upvote 0

BillMeyer

Well-Known Member
Licensed User
Longtime User
@MrKim
You say that you have the phone (the S7) - Well then connect it to your IDE, then go to the Designer, click on WYSIWYG Designer and then Connect.

Now look a the bottom left of your screen. You should see:
upload_2017-10-26_10-29-21.png


Now go to Variants and click on New Variant button. You will get this:
upload_2017-10-26_10-31-17.png


Enter those dimensions here (that is the 1080x1920x2.625 - or whatever your device returns) and press OK

You will get this:
upload_2017-10-26_10-33-18.png


and there you will see the dimensions required with a scale of 1 of your connected device. If you now press "Yes" - it will be added correctly to your Variant List.

I hope this short trick helps - BUT - out of experience - PLEASE listen to @NJDude and @Erel 's advice - it will save you much heartache.
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
There is no meaning to this value without the scale.

The orientation is considered when it looks for the best fit.

I agree with @NJDude that you should use as few as possible variants. Anchors and designer scripts are easier to work with.

I understand. The reality is this is an issue only because I was forced to make a landscape version of an app that I intended to be portrait only.

But that still doesn't answer my question. The layouts I have (along with their designer scripts - I do have those as well) will work fine with pretty much any screen res, as long as it correctly picks portrait or landscape. So for this one activity with this app, at this time, all I want to do is insure that my app correctly selects portrait or landscape.

FYI, this is a setup screen for an industrial app. It will be used by MIS to setup the program for the users and after that it will NEVER be used again unless the company changes their server configuration. So it doesn't need to be pretty, it just needs to fit on the screen. My time needs to be spent making the rest of the app (which has LOTS of designer scripts as well as code to properly place things) bulletproof.

BTW, I played around with anchors for a couple of hours a while back and could NEVER make them work to my satisfaction. I realize I am probably missing something, probably obvious. I will start another thread to talk about my issues.

-
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
Once again, using the designer scripts is the way to go, if you want to handle both orientations perfectly, then you will have to create 1 design for portrait and 1 for landscape and all that can be done with 1 single script.

I know you will see the light soon and you will throw away all those variants. ;)
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
Once again, using the designer scripts is the way to go, if you want to handle both orientations perfectly, then you will have to create 1 design for portrait and 1 for landscape and all that can be done with 1 single script.

I know you will see the light soon and you will throw away all those variants. ;)

Fine and dandy for the future. Right now I have one activity and all I want to do is insure that when it loads it correctly picks a portrait or landscape. variant. How do I do that? I can cut and past my existing layout into 10 more variants in about 10 minutes if I need to. It will take me hours if not days to figure out how to properly locate 30 views on multiple panels using one variant.
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
@MrKim
You say that you have the phone (the S7) - Well then connect it to your IDE, then go to the Designer, click on WYSIWYG Designer and then Connect.

Now look a the bottom left of your screen. You should see:
View attachment 61020

Now go to Variants and click on New Variant button. You will get this:
View attachment 61021

Enter those dimensions here (that is the 1080x1920x2.625 - or whatever your device returns) and press OK

You will get this:
View attachment 61022

and there you will see the dimensions required with a scale of 1 of your connected device. If you now press "Yes" - it will be added correctly to your Variant List.

I hope this short trick helps - BUT - out of experience - PLEASE listen to @NJDude and @Erel 's advice - it will save you much heartache.

Yes, I know how to do that but that only resolves the one device. My issue is, for some reason my S7 is choosing a landscape rather than a portrait variant. Barring a way to prevent this I am hoping someone could give me a list of variants to use which would more or less guarantee Horizontal or vertical would be chosen correctly regardless of the device. Or at least explain to me what the logic is behind the S7 is choosing the wrong one so I could make some educated guesses about what to use.
 
Upvote 0

edgar_ortiz

Active Member
Licensed User
Longtime User
MrKim

You can always check in "Activity_Create" or in "Activity_Resume"

B4X:
If Activity.Height > Activity.Width Then
        ' Your choice
Else
        ' Your choice
End If

Regards,

Edgar
 
Upvote 0

BillMeyer

Well-Known Member
Licensed User
Longtime User
This is a shot in the dark. I cannot test my theory as I have the S6 and S8, but for some strange reason it seems to me to be a device issue that it is selecting the closest "fitting" screen and orientation and it's brain is telling it the orientation is "Landscape".

So, may I suggest a "cumbersome" work around that might solve your problem by setting the orientation forcefully in your code. To do this:

1. In your globals: "Dim ph1 as phone"
2. In your sub Activity_Create, right after loading your layout, enter: "ph1.SetScreenOrientation(1)"

This still does not answer your question of why only on the S7 but will go some length to preserve your sanity.

I trust this helps.
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
I went ahead and solved my problem by writing a designer script using
B4X:
AutoScaleAll
If Landscape Then
...
Else
...
End
which solves the problem so their is no need for anyone to post any more solutions.

But I would still like to know:

Why does my S7 choose a landscape variant from the above choices when it is in portrait mode?
What variants should I include to insure that the appropriate portrait/landscape is chosen?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
What variants should I include to insure that the appropriate portrait/landscape is chosen?
As several us told you a few times, try to use a single variant.

Why does my S7 choose a landscape variant from the above choices when it is in portrait mode?
Which variant was chosen? What is the value of Log(GetDeviceLayotuValues) with this device?
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
As several us told you a few times, try to use a single variant.

I have done that, but I am still trying to understand why this happens

Which variant was chosen? What is the value of Log(GetDeviceLayotuValues) with this device?

I am not sure which Variant was chosen as they both have exactly the same layout.

1080 x 1920, scale = 3.0 (480 dpi) - Portrait
1920 x 1080, scale = 3.0 (480 dpi) - Landscape

It occurs to me a HUGE time-saver (at least for me) would the ability to do a manual layout and then have the designer generate a designer script for all the views using the appropriate %x and %y values. It would be a great starting point. You would need to be able to do it for both portrait and landscape. Should I submit this as a feature request?
 
Last edited:
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
I resolved this issue with one layout and a designer script. I want to thank everyone for their thoughts and ideas.
I have a confession to make. My partner and I have a Windows program with over 600 forms and reports. We have been dong this together for almost 30 years.
He lays them out and I make them work. Unfortunately he doesn't do Android.
I had forgotten how little patience I have for this part of the process. I really appreciate everyone's patience and help as I grapple with the part of the process I really have no interest in.
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
Good to know you sorted out.

It seems you finally saw the light since now you are using 1 layout and 1 script. :D
Like I said, in this case I would have preferred not. If I could have added another layout or two and more or less guaranteed i would be could on most devices I would have done that - in ten minutes, but I never got an answer to that. Doing the Des. script took hours.
As I mentioned above it would be really nice if the designer would generate a %x/%y script based on a manual layout. That could save hours.
 
Upvote 0
Top