Search code examples
androidviewscreens

custom View Display problem on different android screens


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?


Solution

  • 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;