如何通过单击菜单中的按钮来增加线性布局的大小... android studio
我这样做但是没有用:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.Larger){
LinearLayout layout = (LinearLayout)findViewById(R.id.asdf);
ViewGroup.LayoutParams params = layout.getLayoutParams();
params.height = ++params.height;
params.width = ++params.width;
layout.setLayoutParams(params);
}
return super.onOptionsItemSelected(item);
}
这是我的布局:
答案 0 :(得分:0)
您的代码增加了高度和宽度的值,但比例非常小,
试试这个:
if(id == R.id.Larger){
LinearLayout layout = (LinearLayout)findViewById(R.id.asdf);
ViewGroup.LayoutParams params = layout.getLayoutParams();
params.height = params.height + 100;
params.width = params.width + 100;
layout.setLayoutParams(params);
}