本文实例讲述了Android编程获取手机屏幕分辨率大小的方法。分享给大家供大家参考,具体如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
import android.app.Activity; import android.os.Bundle; import android.util.DisplayMetrics; import android.widget.TextView; public class A03Activity 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); mTextView01=(TextView)findViewById(R.id.myTextView01); DisplayMetrics dm= new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); String s= "屏幕的分辨率为:" +dm.widthPixels+ "*" +dm.heightPixels; mTextView01.setText(s); } } |
希望本文所述对大家Android程序设计有所帮助。