简体   繁体   English

在图像比例 android 上调整 IMAGEVIEW 的大小

[英]Resizing IMAGEVIEW on image scale android

I have an image inside an imageview in android.我在 android 的 imageview 中有一个图像。

I am scaling the image using scaletype(MATRIX) via code similar to this:我通过类似于以下的代码使用 scaletype(MATRIX) 缩放图像:

                       mtrx.postScale(scale, scale);
                 imageView.setImageMatrix(mtrx);
            imageView.setScaleType(ScaleType.MATRIX);
            imageView.invalidate();

Now, this does properly resize the image contained in the ImageView, which is nice, but what I need is to reposition the image to location 0,0 within the imageview and then resize the imageView itself to the size of the scaled image.现在,这确实正确调整了 ImageView 中包含的图像的大小,这很好,但我需要将图像重新定位到 imageview 内的位置 0,0,然后将 ZE9E20DE7B6F7D42815E27F0Z 本身调整为缩放后的图像大小。

So far every Idea I have come up with to attempt to reuse the same imageView doesn't seem to work, or I am just doing something wrong.到目前为止,我想出的每一个想法都试图重用相同的 imageView 似乎不起作用,或者我只是做错了什么。

Is my only way to accomplish this to destroy the imageview, resize the bitmap, create a new imageview containing the new bitmap created at scale and adding the view back the layout? Is my only way to accomplish this to destroy the imageview, resize the bitmap, create a new imageview containing the new bitmap created at scale and adding the view back the layout?

I'd really like NOT to do that.. I am bumping up against the 16 Meg heap limit as it is with things.我真的不想那样做.. 我遇到了 16 Meg 堆限制,因为它与事情一样。 How do I tell the matrix to move the image to position 0,0 in the imageView (the imageView is initially created with scaletype center, after it has scaled the image smaller? And how do I then tell the imageView, hey you are now only as big as the scaled Image? How do I tell the matrix to move the image to position 0,0 in the imageView (the imageView is initially created with scaletype center, after it has scaled the image smaller? And how do I then tell the imageView, hey you are now only和缩放的图像一样大?

Thanks in advance.提前致谢。

Setting your image view to "Adjust View Bounds" appears to do the trick.将您的图像视图设置为“调整视图边界”似乎可以解决问题。

Here's what the docs have to say:这是文档必须说的:

Set this to true if you want the ImageView to adjust its bounds to preserve the aspect ratio of its drawable.如果您希望 ImageView 调整其边界以保持其可绘制对象的纵横比,请将其设置为 true。

You can do this by either using android:adjustViewBounds="true" or in code with imageView.setAdjustViewBounds(true) .您可以使用android:adjustViewBounds="true"或在代码中使用imageView.setAdjustViewBounds(true)来执行此操作。

Set "Adjust View Bounds" true, and then set the scale type to "fitXY" finally adjut layout_width and height.将“Adjust View Bounds”设置为true,然后将缩放类型设置为“fitXY”,最后调整layout_width和height。 You will see that the image resizes.您将看到图像调整大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM