项目中一些活动列表的展示图片如果没有的话,展示活动的商品图片,图片大小按商品原图展示。这时就需要动态修改imageview大小
xml代码中
android:layout_width="wrap_content"
android:layout_height="wrap_content"
java代码中
ViewGroup.LayoutParams lp = testImage.getLayoutParams();
lp.width = LayoutParams.WRAP_CONTENT;
lp.height = LayoutParams.WRAP_CONTENT;
testImage.setLayoutParams(lp);
其中LayoutParams.WRAP_CONTENT还可以是LayoutParams.MATCH_PARENT或者int数值