// 屏幕方面切换时获得方向
if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
setTitle("landscape");
}
if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
setTitle("portrait");
}
// 获得屏幕大小1
WindowManager manager = getWindowManager();
int width = manager.getDefaultDisplay().getWidth();
int height = manager.getDefaultDisplay().getHeight();
// 获得屏幕大小2
DisplayMetrics dMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dMetrics);
int screenWidth = dMetrics.widthPixels;
int screenHeight = dMetrics.heightPixels;
利用getLayoutParams()方法和setLayoutParams()方法。
1、首先利用getLayoutParams()方法,获取控件的LayoutParams。
eg:LayoutParamslaParams=(LayoutParams)imageView.getLayoutParams();
2、设置该控件的layoutParams参数
eg: laParams.height=xxx;
laParams.width=yyy;
3、将修改好的layoutParams设置为该控件的layoutParams.
eg:imageView.setLayoutParams(laParams);