Android Question Cross-platform grid code: B4A is not equal B4J

peacemaker

Expert
Licensed User
Longtime User
HI, All

The project is attached: the same code for B4J and B4A.
At start the objects are OK at 0.0 coords.
Under Windows B4J compilation works ideally (object moving along the grid), but under Android - objects are not fit a bit, if to move both objects and try to fit the circles.
Why ?
 

Attachments

  • TempDownload.png
    TempDownload.png
    22.7 KB · Views: 111
  • b4xVectEdit_v0.15.zip
    14.4 KB · Views: 122
  • TempDownload.png
    TempDownload.png
    24.4 KB · Views: 117
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Better to apply the grid after the boundaries are set:
B4X:
mRoot.Left = ApplyGrid(Max(0, Min(mRoot.Parent.Width - mRoot.Width, mRoot.Left + X - DownX)))
mRoot.Top = ApplyGrid(Max(0, Min(mRoot.Parent.Height - mRoot.Height, mRoot.Top + Y - DownY)))

2. The issue is probably related to the AutoScaleAll in the layout. It will cause the views size to slightly change. Remove it.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Thanks, Erel.
But AutoScaleAll does not fully help.
 
Last edited:
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Works as expected on my Samsung
Tks for test, Klaus. But check on PC - it's ideally fit at any position - if to fit the circles. But not under Android. I also use Samsung.
 

Attachments

  • TempDownload.png
    TempDownload.png
    10 KB · Views: 79
  • TempDownload.png
    TempDownload.png
    9 KB · Views: 70
  • TempDownload.png
    TempDownload.png
    10 KB · Views: 75
Last edited:
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
B4X:
Private GridSize As Int = 5dip

B4J log is 5 each step of the grid.
But B4A is logging as 7.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I used the project from post #5 as it is and I logged the GridSize, it is 15 on my smartphone with a scale of 3.
AutoScaleAll commented or not has no influence.
To me, removing dip sounds very strange, because this would mean a different behavior on devices with same physical dimensions but different pixel scales.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
If GridSize As Int = 5 without dip, but all other classes variables are with dip and the grid works OK on 2 phones + emulator:
1714325067695.png

If all without dip:
1714325106074.png
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Yes, maybe not ideal within the screen, but the topic is about the cross-platformity. I'm just try to make to be the fully same at 2 platforms.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I'm just try to make to be the fully same at 2 platforms.
To me, this means dip values for B4A.
A same physical point, in B4A, will be displayed almost the same physical size on any Android device.
Without dip values a point could be one half or one third of the size of a point in B4J.
Dip values have no effect in B4J.
But, again, this is just my opinion.
But, I do not understand why it works on my devices and not on yours. Are we really using exactly the same project ?
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
It works, but the grid step and the scale are different comparing to the B4J. Is it OK ?
I guessed, if the code is the same at both systems, so the scale should be same, isn't it ?
But scales of each object are different on PC and Android.
1714326810267.png


Step of 5dip is logged as 5 and 7 at PC and Android.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Hmm, wait, if 5dip grid and the layout without "AutoScaleAll" - seems, is got OK...
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
GetDeviceLayoutValues.Scale = 2.8125
What device do you have ?
Mine is 3
What do you get with:
B4X:
    Log("GridSize = " & GridSize)
    Log(GetDeviceLayoutValues.Scale)
    Log(xui.Scale)
I get:
GridSize = 15
3
3

Which is coherent.
AutoScaleAll has no effect, commented or uncommented.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Log("GridSize = " & GridSize) Log(GetDeviceLayoutValues.Scale) Log(xui.Scale)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
*** mainpage: B4XPage_Created
GridSize = 14
2.8125
2.8125
 
Upvote 0
Top