1

I change the Android emulator 2.2 resolution to WVGA800. But when I tried to get the width and height, it was still 320 x 533. I tried another application using the surfaceview, and it changed to 480 x 800. Why? It confused me. Did I make any mistake in the code or the setting. Thanks for your helping.

public class Mytest extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    DisplayMetrics dm=getResources().getDisplayMetrics();          
    int screenWidth=dm.widthPixels; 
    int screenHeight=dm.heightPixels;  
    this.setTitle("X="+screenWidth+", Y="+screenHeight);
    setContentView(R.layout.main);
}
}
Robin Chiu
  • 31
  • 4

1 Answers1

0

You are getting the pixels after division by pixel density. Peep this hot action: Android: Showing wrong screen resolution

Community
  • 1
  • 1
Will Tate
  • 33,439
  • 9
  • 77
  • 71
  • 1
    What that discussion seems to lack is a link to _why_ the system behaves this way and exactly how to control it. See [How Android supports multiple screens](http://developer.android.com/guide/practices/screens_support.html#support) and following sections - particularly "Density independence" and "Manifest attributes for screens support." Essentially, either you inform the system that you will follow best practices, or the system enforces them for you. – erichamion Mar 04 '11 at 19:49