ImageView

发布时间:2019-08-06 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了ImageView脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

本文介绍日常开发过程中使用ImageView需要了解的知识和注意的地方,例如:ImageView引用图片后上下方区域空白的问题。

ImageView引用图片后上下方区域空白

注:图片本身上下方无空白区域!!!

当我们将一张图片引用到我们指定的ImageView容器中,可能由于图片尺寸、比例等原因,无法铺满整个容器(表述不好),导致白边的出现,而且怎么去也去不掉。如下布局代码:

<LinearLayout
    andROId_layout_width="match_parent"
    android_layout_height="match_parent"
    android_orientation="vertical"/>

    <ImageView
        android_layout_width="match_parent"
        android_layout_height="wrap_content"
        android_src="@mipmap/share_invite"/>

    <TextView
        android_layout_width="wrap_content"
        android_layout_height="wrap_content"
        android_text="测试空白区域文本"/>

</LinearLayout>

如上述布局代码,本身没有任何问题,但是因为图片的尺寸,比例等原因,就可能出现图片和文本之间存在空白区域的问题。

那么怎么解决呢?

其实很简单,我们只需要为ImageView添加以下属性就可以了:

android:adjustViewBounds="true"

adjustViewBounds

我想,你一定会问,这句话代表着什么意思?为什么这样就可以了呢?这里我就给大家简要解释一下:

GOOGLE官方对于adjustViewBounds这个属性是这样介绍的:

谷歌原文:Set this to true if you want the ImageView to adjust its bounds to PReserve the aspect ratio of its drawable.

中文翻译:如果你想要ImageView适应边界,同时保持图片高比,可以将它设置为true。

我们也可以这样理解:将 android:adjustViewBounds 设置为true,即可去除因图片宽高比等原因导致ImageView直接引用图片时上下方存在空白区域的问题。

脚本宝典总结

以上是脚本宝典为你收集整理的ImageView全部内容,希望文章能够帮你解决ImageView所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。