【发布时间】:2019-07-28 02:56:40
【问题描述】:
我有一个图像视图,其中有一个图像,图像边界与 Imageview 的边界不同。如何在Android的Imageview中获取图像的边界。
【问题讨论】:
-
你能发布你的代码吗?
标签: android
我有一个图像视图,其中有一个图像,图像边界与 Imageview 的边界不同。如何在Android的Imageview中获取图像的边界。
【问题讨论】:
标签: android
您可以像这样访问底层图像的大小:
ih=imageView.getMeasuredHeight();//height of imageView
iw=imageView.getMeasuredWidth();//width of imageView
iH=imageView.getDrawable().getIntrinsicHeight();//original height of underlying image
iW=imageView.getDrawable().getIntrinsicWidth();//original width of underlying image
您还可以使用以下方法使图像适合 ImageView 大小:
android:scaleType="fitxy"
android:adjustViewBounds="true"
有关 scaleType 的更多信息,请查看:https://thoughtbot.com/blog/android-imageview-scaletype-a-visual-guide
最好的
【讨论】:
使用
android:scaleType="centerinside"
android:adjustViewBounds="true"
【讨论】: