0

I'm making a puzzle app with animations. The animations look a lot faster on small screens then on larger screens. I'm assuming this is because on a larger screen they are moving a longer distance.

I was going to change the play back speed depending on the screen size. I cn get the screen size in pixcels is there a way to get it in dpi????

Ted pottel
  • 6,869
  • 21
  • 75
  • 134
  • See: http://stackoverflow.com/questions/8295986/how-to-calculate-dp-from-pixels-in-android-programmatically – powerj1984 Aug 30 '13 at 23:10
  • Are you locking animations to a particular framerate? If not, the speed of your animations is probably dependent upon how fast the device can draw the object(s) in question. – Philip Conrad Aug 30 '13 at 23:11
  • The issue is that it takes the same amount of time to move a object from the right side to left side of the screen on both small screens (2 inches whide, or big screens 8 inches whide.) – Ted pottel Aug 31 '13 at 12:10

4 Answers4

0

There is your answer: Get screen dimensions in pixels . This however, may not solve your problems. You should check your animation speeds, because I'm pretty sure, that it is not from the differences in the displays. You should post some code, for better help. Hope this helps.

Community
  • 1
  • 1
ya-ivanov
  • 516
  • 2
  • 11
0

If you want the the display dimensions in pixels you can use getSize:

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;

If you're not in an Activity you can get the default Display via WINDOW_SERVICE:

WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();

Before getSize was introduced (in API level 13), you could use the getWidth and getHeight methods that are now deprecated:

Display display = getWindowManager().getDefaultDisplay(); 
int width = display.getWidth();  // deprecated
int height = display.getHeight();  // deprecated

Referred from : How to get screen dimensions

Community
  • 1
  • 1
Shakeeb Ayaz
  • 6,200
  • 6
  • 45
  • 64
0
Display display = getWindowManager().getDefaultDisplay();

int width = display.getWidth();
int height = display.getHeight();

OR

 Display display = getWindowManager().getDefaultDisplay();
 Point sSize = new Point();
 display.getSize(sSize);
 int width = sSize.x;
 int height = sSize.y;
Umer Farooq
  • 7,356
  • 7
  • 42
  • 67
0

you can use this:

 Display display = getWindowManager().getDefaultDisplay();
 Point sSize = new Point();
 display.getSize(sSize);
 int width = sSize.x;
 int height = sSize.y;

you can also use this for inches:

    float mXDpi;
    float mYDpi;
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    mXDpi = metrics.xdpi; 
    mYDpi = metrics.ydpi;
    float  mMetersToPixelsX = mXDpi / 0.0254f; 
    float  mMetersToPixelsY = mYDpi / 0.0254f;
Piyush
  • 18,895
  • 5
  • 32
  • 63
  • Hi,Thank you for taking the time to answer my question, but I was trying to get the screen size in inches, not pixcles. Is there a way to do this????? – Ted pottel Aug 31 '13 at 12:09