獲取螢幕的寬度和高度然後計算出你控制元件的大小,然後只進去就行了,,,如果全屏顯示就設定LayoutParams.MATCH_PARENT如果自適應就設定LayoutParams.WRAP_CONTENT int width = getScreenWidth/2; int height = getScreenHeight/2; imageView].setLayoutParams(new LayoutParams(width, height)); 全屏 imageView].setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); 自適應 imageView].setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); public int getScreenWidth() { WindowManager wm = (WindowManager) sInstance .getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); return display.getWidth(); }
獲取螢幕的寬度和高度然後計算出你控制元件的大小,然後只進去就行了,,,如果全屏顯示就設定LayoutParams.MATCH_PARENT如果自適應就設定LayoutParams.WRAP_CONTENT int width = getScreenWidth/2; int height = getScreenHeight/2; imageView].setLayoutParams(new LayoutParams(width, height)); 全屏 imageView].setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); 自適應 imageView].setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); public int getScreenWidth() { WindowManager wm = (WindowManager) sInstance .getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); return display.getWidth(); }