Android Question How to position view correctly for different resolutions

Sanxion

Active Member
Licensed User
Longtime User
Hi everyone

At the risk of incurring the wrath of my respected forum members, I am going to ask a question that I admit has been asked before - several times - but I am still none-the-wiser concerning its correct resolution.

Allow me to explain.

I have a panel that I center on the screen using:

Panel.Left = (Activity.Width - v.Width) / 2
Panel.Top = (Activity.Height - v.Height) / 2

This seems to have the effect of centering the panel on all screens/resolutions I have tried so far...which is great.

However, the panel contains a main label (some text) and several other labels (vowel markings) around that text. When I position the labels in the designer and test it on my device (7", 1920 * 1080), the labels are all positioned correctly. However, when I try it on a different device, the vowel marking labels are moved out of position - which is a significant problem.

How therefore do I ensure the labels in the panel are scaled/positioned correctly when moving from device to device? What I am trying to accomplish is not that complicated so I hoping there is a simple method of ensuring it remains in position.

Thank-you in advance!
 

klaus

Expert
Licensed User
Longtime User
What exactly are you doing?
If the other objects have the Panel as parent object they will be moved with the Panel.

Where do you set:
Panel.Left = (Activity.Width - v.Width) / 2
Panel.Top = (Activity.Height - v.Height) / 2

Do you scale the views somewhere )
 
Upvote 0

Sanxion

Active Member
Licensed User
Longtime User
What exactly are you doing?
If the other objects have the Panel as parent object they will be moved with the Panel.

Where do you set:
Panel.Left = (Activity.Width - v.Width) / 2
Panel.Top = (Activity.Height - v.Height) / 2

Do you scale the views somewhere )

Yes the other objects have the panel as the parent object. Should the surrounding labels have the panel as the parent object or the center label or something else?

(Where do you set:) This is set in Activity_Create.

I am not scaling the views anywhere - as far as I know.

This is set in the designer:

'All variants script
AutoScaleAll
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I am not scaling the views anywhere - as far as I know.

This is set in the designer:

'All variants script
AutoScaleAll
AutoScale in the Designer means that you are scaling the views.
But this scales everything with the same factor, in this case there should be no problem.
All views having the Panel as parent view are moved with the Panel when this one is moved?
All the other views will not.

You should set the positioning in the DesignerScripts and not in the code, like:
Panel.HorizontalCenter = 50%x
Panel.VerticalCenter = 50%y
 
Upvote 0

Sanxion

Active Member
Licensed User
Longtime User
Afternoon all

I have attached a small test project that demonstrates my issue.

A single panel comprising of a main text label (two words) and a series of labels (vowel markings) that surround it. I have included a .jpg that shows the position of all the labels correctly on my virtual device.

If somebody could please modify the project to ensure that the surrounding labels maintain their positions relative to the central one regardless of the screen size/resolution, I would be enormously grateful as my project is entirely dependent upon the surrounding labels (vowel marks) maintaining their correct position.

Thank-you.
 

Attachments

  • PositionTest.zip
    38.5 KB · Views: 135
Upvote 0
Top