setLayoutParams()无效问题


iv_address = (ImageView) findViewById(R.id.iv_address);//加载xml布局的imageview
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParam)siv_address.getLayoutParams();//获得layoutParams 
//写你的对layoutParams更改代码
iv_address.setLayoutParams(layoutParams);//更新为你想设置的layoutParams

运行后无效,怀疑是因为设置的layoutParams为同一个引用,系统认为没改变所以设置没刷新,待后面学到相关后研究一下

更改为new一个对象后设置成功:

RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(iv_address.getLayoutParams()); 

你可能感兴趣的:(setLayoutParams()无效问题)