【问题标题】:Image bounds inside image view图像视图内的图像边界
【发布时间】:2019-07-28 02:56:40
【问题描述】:

我有一个图像视图,其中有一个图像,图像边界与 Imageview 的边界不同。如何在Android的Imageview中获取图像的边界。

【问题讨论】:

标签: android


【解决方案1】:

您可以像这样访问底层图像的大小:

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

最好的

【讨论】:

    【解决方案2】:

    使用

         android:scaleType="centerinside"
         android:adjustViewBounds="true"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-19
      • 1970-01-01
      • 2016-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多