0

I am making a game that displays animated characters on the screen Now I am at the stage where i want it to display correctly on other devices as well increase the screen resolution on my own device and have it still display correctly for this I want to get the scale factor so I can change all my pixel values to DP values however the display metrics does not change no matter what I change the screen resolution to

for example

this.getHolder().setFixedSize(1024, 768);
scale = getResources().getDisplayMetrics().density;
DisplayMetrics dm = new DisplayMetrics();
((Activity) getContext()).getWindowManager().getDefaultDisplay()
    .getMetrics(dm);
float xDpi = dm.xdpi;
float yDpi = dm.ydpi;

Now no matter what I change 'setfixedsize ' to, both xdpi and scale stay the same even though it does show the increased screen resolution on the display

heckubiss
  • 5
  • 2
  • http://stackoverflow.com/questions/5078808/android-showing-wrong-screen-resolution?rq=1 – Sean Sep 26 '13 at 21:05

2 Answers2

0

You can get display metrics using below line.

DisplayMetrics metrics = getResources().getDisplayMetrics();
  • As I stated in my question. My issue is not getting the displaymetrics. My issue is understanding why when I change resolution using setFixedSize the displaymetrics dont change, yet my screen shows a different resolution – heckubiss Sep 27 '13 at 19:19
  • 1
    I don't think you can actually change the values of device displaymetrics, you will have to read displaymetrics and change the size of your layouts accordingly. –  Sep 29 '13 at 07:42
0

This is my code for display wallpaper may be its help full=====>

    Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    float w = size.x;
    float h = size.y;
    width = ((w)/1000);
    height = ((h)/1000);
    Log.d("width===>", String.valueOf(width));
    Log.d("height===>", String.valueOf(height));

(OR)

    metrics = Resources.getSystem().getDisplayMetrics();
    float w=metrics.widthPixels;
    float h=metrics.heightPixels;

    width = ((w)/1000);
    height = ((h)/1000);
    if(width == 0.72f && height == 1.28f){
        width=1.08f;
        height=1.776f;

    }
    Log.d("width===>", String.valueOf(width));
    Log.d("height===>", String.valueOf(height));
Manthan Patel
  • 1,784
  • 19
  • 23