我使用ImageView在项目“ assets”文件夹下显示jpg文件,其固有尺寸为:1280x854,已通过调用myDrawable.getIntrinsicWidth()和myDrawable.getIntrinsicHeight()进行确认。

我的图像视图实现了捏缩放,因此图像可以放大到2倍。然后执行以下代码:

Drawable drawable = getDrawable();
Rect bounds =drawable.getBounds();
Log.i("activity", String.format("drawalbe : top:%d, left: %d, (%d, %d)", bounds.top, bounds.left, bounds.width(), bounds.height()));


无论当前比例是多少,可绘制边界始终为1280x854,顶部,左侧始终为0、0。

边界不应该相应地缩放吗?有人可以给我一些提示吗?谢谢。

最佳答案

这是因为this

比例矩阵仅影响视图的绘制方式,而不会更改其尺寸。

尽管您可以创建图像大小的Rect并使用Matrix.mapRect(Rect r)将相同的比例矩阵应用于Rect,并且Rect将具有比例尺。

07-24 09:50
查看更多