private Button mbtn;
mbtn = (Button) findViewById(R.id.btn_test);
LayoutParams lp;
lp=mbtn.getLayoutParams();
lp.width=100;
lp.height=200;
mbtn.setLayoutParams(lp);
//在代碼中設置界面大小的方法:
Display display = getWindowManager().getDefaultDisplay(); // 為獲取屏幕寬、高
Window window = getWindow();
LayoutParams windowLayoutParams = window.getAttributes(); // 獲取對話框當前的參數值
windowLayoutParams.width = (int) (display.getWidth() * 0.7); // 寬度設置為屏幕的0.95
windowLayoutParams.height = (int) (display.getHeight() * 0.1); // 高度設置為屏幕的0.6
windowLayoutParams.alpha = 0.5f;// 設置透明度