android获取屏幕的高度和宽度用到WindowManager这个类,两种方法:
1、WindowManager wm = (WindowManager) getContext()
.getSystemService(Context.WINDOW_SERVICE);
int width = wm.getDefaultDisplay().getWidth();
int height = wm.getDefaultDisplay().getHeight();
2、WindowManager wm = this.getWindowManager();
int width = wm.getDefaultDisplay().getWidth();
int height = wm.getDefaultDisplay().getHeight();
// 动态设置imageview的宽高
- image = (ImageView)findViewById(R.id.ImageView01);
- //height = image.getHeight();
- //width = image.getWidth();
- //Log.d(TAG, "height: " + height);
- //Log.d(TAG, "width: " + width);
- LayoutParams para;
- para = image.getLayoutParams();
- para.height = 300;
- para.width = 300;
- image.setLayoutParams(para);
浙公网安备 33010602011771号