2016-05-16 83 views
-3

我有一個按鈕,我想更改邊距。 這裏是我的代碼:Android:layoutParams.setMargins()更改視圖的大小

RelativeLayout.LayoutParams buttonParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); 
       buttonParams.setMargins(r.getWidth()/3 * 2, r.getHeight() * 5/7, 0, 0); 
       b.setWidth(r.getWidth()/4); 
       b.setHeight(r.getWidth()/8); 
       b.setLayoutParams(buttonParams); 

,當我改變setMargins b的值的大小變化。爲什麼會出現這種情況,我該如何解決?

回答

0

我認爲它的,因爲你有

b.setWidth(r.getWidth()/4); 
    b.setHeight(r.getWidth()/8); 

前設置佈局PARAMS

刪除設置寬度和高度b不改變其dimesions。

乾杯,
Sha