最近在做一个动态壁纸项目,我在Engine的onCreate方法里,去添加两只“蝴蝶”时,我使用了addView(imageview,new LayoutParams(width,height))方法,但是无论我怎么改变width和height,“蝴蝶”的大小都没有发生变化。我在网上查了下,貌似方法的使用是没有问题的,那么我应该怎么去调整imageview 的大小?
这个是效果图,下面是设置的代码:
LinearLayout.LayoutParams ivBlueParams=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
ivBlueParams.gravity= Gravity.CENTER;
LinearLayout.LayoutParams ivYellowParams=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
widgetGroup.addView(ivYellowButterfly,ivYellowParams);
widgetGroup.addView(ivBlueButterfly,ivBlueParams);
PHP中文网2017-04-17 17:24:59
You should set ivYellowButterfly
与ivBlueButterfly
的setLayoutParams()
或者获取ivYellowButterfly
与ivYellowButterfly
的LayoutParams
to set it up.