zoukankan      html  css  js  c++  java
  • [图形图像]---浅析android里面的ImageView的ScaleType属性

    在我们写UI布局的时候,常使用ImageView控件,控件布局写好后,.9.png图片如何填充这个ImageView控件,此时就有ImageView的ScaleType属性决定。

    ScaleType是ImgeView的一个内部枚举类:ImageView$ScaleType,它决定了图片对View视图的填充结构。API解释如下:Options for scaling the bounds of an image to the bounds of this view.它一共有7种填充模式,下面一个一个说来。

    首先我们来看一张完整的图片720*1280:

    Screenshot_2015-01-06-09-00-58

    这是一张手机截图,假如我们将这张图片作为图片中ListView中的item最左边的ImageView的src

    1、CENTER/centerCrop

    Api解释:Center the image in the view, but perform no scaling.图片不执行缩放,直接将图片在view中居中显示。这个属性会出现三种不同结果:1、图片分辨率大于ImageView控件的实际像素个数----->截取图片正中心(如图1.1);2、图片分辨率小于ImageView控件的实际像素个数----->图片直接居中显示到ImageView控件中心位置(如图1.2);3、图片分辨率正好等于ImageView控件像素实际个数----->图片与ImageView控件正好完全匹配显示(说明:view视图控件存在像素个数由手机屏幕尺寸与你设定的dpi有关系,这里就不多解释了,可以直接看我的博客:[图形图像]---位图Bitmap、分辨率Resolution、像素Pixel(px)、距离密度dpi,基本概念与相互之间的联系)。

    center1.1      center1.2

    2、CENTER_CROP/centerCrop

    Api解释:Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view (minus padding). The image is then centered in the view.

    这个属性是保证原图片的长宽比例不变,然后长与宽同时等比例缩放,确保填充满整个ImageView视图这个属性可能导致图片放大或者缩小以便确保图片填充满整个ImagView视图,长宽仅有一个现实完整。1、如果图片长宽像素均大于ImageView控件实际像素个数,则需要缩小,缩小比例取二者中小值(如图2.1)2、如果图片长宽像素有一项小于ImageView控件实际像素个数,则需要放大,放大比例取二者大值。(二者是指,图片长像素除以ImagView控件实际长像素得到的值与图片宽像素除以ImagView控件实际宽像素得到的值)。

    center_crop2.1

    ---未完待续

  • 相关阅读:
    1461. Check If a String Contains All Binary Codes of Size K
    1460. Make Two Arrays Equal by Reversing Sub-arrays
    1466. Reorder Routes to Make All Paths Lead to the City Zero
    1464. Maximum Product of Two Elements in an Array
    js 获取select的值 / js动态给select赋值【转】
    js在HTML中的三种写法【转】
    php中 elseif和else if 的区别【转】
    PhpStorm 常用快捷键
    PhpStorm 2018最新汉化包 解决”设置”不可用问题【转】
    PHP json_encode里面经常用到的 JSON_UNESCAPED_UNICODE和JSON_UNESCAPED_SLASHES【转】
  • 原文地址:https://www.cnblogs.com/android001/p/4311518.html
Copyright © 2011-2022 走看看