0

i have extended View and override onDraw and onSizechanged so i can draw on the screen after i have the full height and width of the screen.But when i tried on my phone the imgs are slightly in different position than that i have defined.Also i have define actual values(in px) in my code and i think i can't use dip at least i don't know....

What can i do to make it seems the same on many screens,when i'm not using Layouts and i do it on code?

stelios
  • 1,027
  • 3
  • 14
  • 19

1 Answers1

0

Make images feel same on different screens, you have to first identify height and width of device and according to it you should write some method that will set your image at place where you want on different screens.

To get height and width of screen you have to write this method at start of activity:

float ht,wt;
    DisplayMetrics displaymetrics = new DisplayMetrics();
            getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
            ht = displaymetrics.heightPixels;
            wt = displaymetrics.widthPixels;
halfer
  • 19,824
  • 17
  • 99
  • 186
chikka.anddev
  • 9,569
  • 7
  • 38
  • 46
  • should i write this in the method onSizeChanged() or outside of this(not implement onsizechanged at all) in the constructor of the activity? – stelios Jan 28 '11 at 13:14
  • i have try it and i think that either i use onsizechanged with getWidth and getHeight or displaymetrics i have the same results...so should i just scale make my images to fit to any screen?(that;s my real problem,images in smaller screens cover each other) – stelios Jan 28 '11 at 15:09