如何以编程方式调整ImageView的大小
问题描述:
我想在触摸ImageView时调整其大小.像在Google地图中或在移动浏览器中进行缩放一样,将其调整大小将是完美的,但是只要触摸它就可以调整大小.有可能吗?
I want to resize an ImageView when I touch on it. It will be perfect to resize it like when you do the zoom in google maps or in a mobile browser but if just touching it I can resize it will be enough. Is that possible?
答
只需捕获触摸此ImageView的事件即可,而不仅仅是调整高度&重量:
Just catch the event of touching this ImageView and than just adjust height & weight :
touched_image_view.getLayoutParams().height += 20;
touched_image_view.getLayoutParams().width += 20;
或者您可以只创建并设置新的LayoutParams:
Or you can just create and set new LayoutParams :
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(100, 100);
touched_image_view.setLayoutParams(layoutParams);
希望有帮助.