Android Question Screen Coord's on different devices

james_sgp

Active Member
Licensed User
Longtime User
Hi,
I`m trying to make a jigsaw type game, the user drags images and I check to see if they are at or near to the reference position for that piece. It works perfectly on one device (Samsung S8+ which I developed it on); but when I move to a device with a smaller screen I can`t get me head around how I need to manipulate the reference position.

S8+ : 1080 x 2009 (2.625 Scale)
ASUS : 480 x 854 (1.5 Scale)

Example, correct position for a piece:
S8+ = 929, 148
ASUS = 375, 81

What am I missing to manipulate these to have a set reference point for different screen sizes?


UPDATE:

The closest I can do is:

[Reference point X] / [screen X] & [Reference point Y] / [screen Y]
But that's giving me an error of -3.17% in X & 2.33% in Y, I could possibly work with that but is there a better way?
 
Last edited:

james_sgp

Active Member
Licensed User
Longtime User
Erel,

Thanks problem identified to being the onscreen menu bar (S8+) and not on the ASUS Vibe; so meant screen dimensions where not matching.

James
 
Upvote 0

james_sgp

Active Member
Licensed User
Longtime User
Hi still getting funny results, looking at the device's activity.width & activity.height & scale they seem wrong... (confirmed screen dimensions given by activity, from the Visual Designer too).

Galaxy S8+ = 1080 x 2094 (compared to 320 x 480, scale 1) thats 3.375 x 4.3625 scale..., but B4A says scale is 2.625?
ASUS Vibe = 480 x 854 (compared to 320 x 480, scale 1) thats 1.5 x 1.7792 scale..., but B4A says scale is 1.5?

So an object that I create round on S8+ (using percentage) is the same size but becoming elliptical on the ASUS... If I switch to defining the object with DIPs it is round but the size is wrong between the two devices.
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
Why are you not following Erel's suggestion of using 100%x and 100%y as your screen dimensions? Then you do not have to even think about pixels or dips or scale values. Drawing a circle with radius 50%x will definitely be circular!
 
Upvote 0

james_sgp

Active Member
Licensed User
Longtime User
I am, I`m loading an image of a circle which should be 30% diameter on the S8+...but I`m not getting that, its becoming elliptical on the ASUS Vibe. If I make it circular again on the Vibe it becomes elliptical on the S8+...

To make it simpler, here is a picture of the problem, and the code I`m using:
B4X:
    BBB.Initialize(File.DirAssets,iv2.tag)
    III.Initialize("iii")
    III.Bitmap = BBB
    GD.SetOnGestureListener(III, "Gesture2")
    III.Gravity = Gravity.fill
    Activity.AddView(III, 16%x, 47%y ,37.15%x, 72%y)
    Log("III width = " & III.Width)
    Log("III height = " & III.height)
 

Attachments

  • Picture1.jpg
    Picture1.jpg
    49.4 KB · Views: 179
Last edited:
Upvote 0

agraham

Expert
Licensed User
Longtime User
If you want it circular you should use only x or y to specify the size and use the same value for width and height. %x values ultimately translate to pixel values and on all devices I know of the pixels are square.

B4X:
   Activity.AddView(III, 16%x, 47%y ,37.15%x, 37.15%x)
 
Upvote 0
Top