我有尺寸的按鈕:的Android layaout PARAMS
btn1.width = 100;
btn2.height = 150;
我用下面的代碼調整:
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) btn1.getLayoutParams();
layoutParams.width = 200;
layoutParams.height = 300;
btn1.setLayoutParams(layoutParams);
當我這樣做:
int newSize = btn1.getWidth;
的新尺寸有值爲100,但不是200.它很好地調整了按鈕的大小,但在調整大小後,btn1.getWidth
仍然保持以前的值。我怎樣才能立即獲得設定的大小?
你有沒有嘗試打印日誌的東西,檢查是否這些行被執行? – guisantogui
您在代碼中添加此行的位置? –
將其添加到WindowsFocuschange上。 – user3240604