// 螢幕方面切換時獲得方向
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);