Android Question Screen designer units?

App Dude

Active Member
Licensed User
Longtime User
I think I understand pixels, scale and dip, but the screen designer seems to have its own units.
Example:
In the designer I have a panel "Panel1", who's top is set at 540
In code, if I log Panel1.top, I get 1769.
My device's scale, from logging 100dip/100 is 3.0
But 1769/540 = 3.28

What I'm trying to do is hide some elements and move up the others below it.
So let's say I have Panel2, Panel3, and Panel4. When the user hits a button, Panel3 is not valid, so I make it invisible, and I want to move Panel 4 up to where Panel 3 was.
But simply using Panel4.Top = Panel3.Top does not work correctly, and not even if I divide by the device scale.

What's the correct way to do this?
Thanks.

1662057248754.png
 

teddybear

Well-Known Member
Licensed User
You'd better upload a small project so that we can see what your designer is.
 
Upvote 0

App Dude

Active Member
Licensed User
Longtime User
You'd better upload a small project so that we can see what your designer is.
Attached. The key here is that the button starts at 50 in the designer, and scale is 3.00, but you'll see 161 on the button when it starts (rounds down to 53) when the button is put back to its "original" position.
 

Attachments

  • ScalingIssueTest01.zip
    305.7 KB · Views: 162
Upvote 0

App Dude

Active Member
Licensed User
Longtime User
Your anchors are wrong. Click on the "check anchors" button and you will see it:

View attachment 133266
The difference that you see is related to AutoScaleAll in the designer script. Feel free to delete it.

Getting a "No problems found" message when I Check Anchors.
With AutoScaleAll off, the location of my widget (Button1 in this example) is now showing correctly on the button, but the button does not return to it's original position. See the example I attached just above this message.

Thanks.
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Attached. The key here is that the button starts at 50 in the designer, and scale is 3.00, but you'll see 161 on the button when it starts (rounds down to 53) when the button is put back to its "original" position.
To put back to its "original" position. you should do Button1.Top = btn1StartY * screenScale instead of Button1.Top= btn1StartY.
you'd better hold its real pixel position to back to its "original" position
 
Last edited:
Upvote 0

App Dude

Active Member
Licensed User
Longtime User
To put back to its "original" position. you should do Button1.Top = btn1StartY * screenScale instead of Button1.Top= btn1StartY.
you'd better hold its real pixel position to back to its "original" position

Ah yes, gotcha. Will try this.
 
Upvote 0

App Dude

Active Member
Licensed User
Longtime User
Bingo! Between AutoscaleAll and using scaled (non-dip) units in code, I have it working now.
Much thanks everyone!
 
Upvote 0
Top