Android开发之屏幕属性
Android屏幕属性有很多,今天学习了全屏,横屏,屏幕宽度和高度的获取。先记录下来,以后再慢慢增加。[java] view plaincopyprint?public class FullScreenAndAttrActivity extends Activity {
/** Called when the activity is first created. */
TextView myTextView = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//设置为无标题栏www.
requestWindowFeature(Window.FEATURE_NO_TITLE);
//设置为全屏模式
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//设置为横屏
//setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setContentView(R.layout.main);
//定义DisplayMetrics对象
DisplayMetrics myDm = new DisplayMetrics();
//取得窗口属性
getWindowManager().getDefaultDisplay().getMetrics(myDm);
//窗口的宽度
int screenWidth = myDm.widthPixels;
//窗口的高度
int screenHeight = myDm.heightPixels;
myTextView = (TextView)findViewById(R.id.myTextView);
myTextView.setText("屏幕宽度:"+ screenWidth + "\n屏幕高度:"+screenHeight);
}
}