2012-10-20 125 views
0

我是android新手,但我想更改佈局的內容,即在另一個佈局內,由於點擊按鈕。如何動態更改子佈局

----------------------------- 
| Button | Button | Button | 
----------------------------- 
|       | 
| Layout that changes  | 
|  dynamically  | 
|       | 
|       | 
------------------------------ 

感謝

回答

0

得到了改變佈局的參考:

LinearLayout changingLayout = (LinearLayout)findViewById(R.id.changing_layout); 

然後獲取它的佈局參數:

LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams)changingLayout.getLayoutParams(); 

然後改變任何你想要放慢參數,例如:

lp.setMargins(newLeft,newTop,newRight,newBottom); 

最後:

changingLayout.setLayoutParams(lp); 

如果你想改變這個佈局包含可見光的意見,我會建議:

view.setVisibility(View.VISIBLE); 

和:

view.setVisibility(View.GONE);