android之檢視模擬器或者真機的螢幕解析度

月盡天明發表於2012-02-15
import android.app.Activity; 
import android.os.Bundle; 
import android.util.DisplayMetrics; 
import android.widget.TextView;
public class EX03_05 extends Activity 
{
  private TextView mTextView01; 
  /** Called when the activity is first created. */ 
  @Override 
  public void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main);
    /* 必須引用 android.util.DisplayMetrics */
    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm); 
    String strOpt = "手機螢幕解析度為:" + dm.widthPixels + " × " + dm.heightPixels; 
    mTextView01 = (TextView) findViewById(R.id.myTextView01); 
    mTextView01.setText(strOpt);
    } 
  }


相關文章