错误代码:
ImageView img1 = (ImageView) findViewById(R.id.icon);
img1.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
解决办法:
ImageView img1 = (ImageView) findViewById(R.id.icon);
img1.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
根据布局修改,比如布局为
RelativeLayout
则使用
new RelativeLayout.LayoutParams