I have many android devices of different screen sizes. I want to make sure that whatever i write the script it should draw the same thing across all the android devices independent of the screen size. So for this I have one relative method as follows:-

 public void dragRel(int relative) {

 }

Where Rel = relative terms, here screen's width and height are both '1' and a location can be expressed by fractions of 1. And so the middle of the screen is always (0.5,0.5).

How do i write a function body that can get the screen size and drag on the screen relatively.

有帮助吗?

解决方案

In general what you want to do is:

  1. Query the device for it's physical dimensions.
  2. Query the device for it's resolution dimensions.
  3. figure out what a single pixel's PHYSICAL width and height are.
  4. Define your items' sizes physically
  5. when you have done this, then when you go to draw, the pixel dimensions of any object become:
    • objPixWide = objPhysWide * pixelWidthPhysical
    • objPixHigh = objPhysHigh * pixelHeightPhysical

If you have these numbers, now your relative values are simply:

  • objPixWide / screenResolutionWidth
  • objPixHigh / screenResolutionHeight
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top