设为首页 加入收藏

TOP

ImageView
2017-10-12 17:57:03 】 浏览:3367
Tags: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直接引用图片时上下方存在空白区域的问题。

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇android如何改变editText控件中部.. 下一篇一个好用的几乎没有Callback的And..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目