0

我是 android 的新手,但由于单击按钮,我想更改布局的内容,即在另一个布局内。

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

谢谢

4

1 回答 1

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);
于 2012-10-20T23:04:04.190 回答