`

ImageView的android:adjustViewBounds属性

 
阅读更多

转自:http://blog.csdn.net/pingchuanyang/article/details/9252689

取值为true时:
Adjust the ImageView's bounds to preserve the aspect ration of its drawable.
调整ImageView的界限来保持图像纵横比不变。
这并不意味着ImageView的纵横比就一定和图像的纵横比相同
 
XML定义里的android:adjustViewBounds="true"会将这个ImageView的scaleType设为fitCenter。不过这个fitCenter会被后面定义的scaleType属性覆盖(如果定义了的话),除非在Java代码里再次显示调用setAdjustViewBounds(true)。
 
如果设置的layout_width与layout_height都是定值,那么设置adjustViewBounds是没有效果的,ImageView将始终是设定的定值的宽高。
 
如果设置的layout_width与layout_height都是wrap_content,那么设置adjustViewBounds是没有意义的,因为ImageView将始终与图片拥有相同的宽高比(但是并不是相同的宽高值,通常都会放大一些)。
 
如果两者中一个是定值,一个是wrap_content,比如layout_width="100px",layout_height="wrap_content"时,ImageView的宽将始终是100px,而高则分两种情况:
(1)当图片的宽小于100px时,layout_height将与图片的高相同,即图片不会缩放,完整显示在ImageView中,ImageView高度与图片实际高度相同。图片没有占满ImageView,ImageView中有空白。
(2)当图片的宽大于等于100px时,此时ImageView将与图片拥有相同的宽高比,因此ImageView的layout_height值为:100除以图片的宽高比。比如图片是500X500的,那么layout_height是100。图片将保持宽高比缩放,完整显示在ImageView中,并且完全占满ImageView。
分享到:
评论

相关推荐

    ImageView android:scaleType的属性

    ImageView 图片显示样式的几种类型。android:scaleType是控制图片如何resized/moved来匹对ImageView的size。

    点按弹出按钮组件

    android:id="@+id/id_arcmenu1" android:layout_width="fill_parent" android:layout_height="fill_parent" zhy:position="left_top" zhy:radius="130dp" > android:layout_width="wrap_content" android:...

    Android中src和background的区别详解

    ImageView中XML属性src和background的区别: background会根据ImageView组件给定的长宽进行拉伸,而src就存放的是原图的大小,不会进行拉伸。src是图片内容(前景),bg是背景,可以同时使用。 此外:scaleType只对...

    androidlayout-marginBottom的值为负数.docx

    为什么有时候像android:layout_marginBottom等变量的... <ImageView  android:layout_width="fill_parent"  android:layout_height="46.0dip"  android:layout_marginBottom="-1.0dip"  android:src="@drawab

    ImageView的属性android:scaleType的作用分析

    代码中的例子如下: 代码如下:<ImageView android:id=”@+id/iv_bit_1″ android:layout_width=”@dimen/passcode_width” android:layout_height=”@dimen/passcode_height” android:scaleType=”fitXY”> &lt...

    九宫格牌翻转游戏demo

    mImageView01 = (ImageView) findViewById(R.id.m1); mButton = (Button) findViewById(R.id.button1); randon(); mImageView01.setOnClickListener(new View.OnClickListener() { @...

    ANDROID实验报告组件布局.pdf

    Android 开发 (实验五) 实验题目:Android 组件布局试验 指导老师: 班 级:计算机科学与技术系班 姓 名: 一、实验目的 1、掌握 Android 组件布局的使用方法 2、学会组件布局的重要属性与应用 3、能够根据需求,...

    [Android应用开发电子书]

    android:id="@+id/ImageView1" android:layout_width="wrap_content" android:layout_height="wrap_content"/> android:id="@+id/zoomout" android:layout_width="wrap_content" android:layout_height="wrap_...

    Android实训购物车页面

    layout_height="153dp" android:layout_width="198dp" android:id="@+id/imageView1" android:src="@drawable/xitongji"> </ImageView> -<LinearLayout android:weightSum="1" android:layout_height="32dp" android...

    Android购物车代码

    weightSum="1" android:layout_height="match_parent" android:layout_width="match_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"> <ImageView android:...

    本地图片上传

    如何利用ImageView上传图片 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:...

    GridView+BaseAdapter的使用

    <ImageView android:id="@+id/img_logo" android:layout_width="60dp" android:layout_height="60dp" android:src="@drawable/ic_launcher" /> android:id="@+id/tv_name" android:layout_width="60dp...

    实例解析Android ImageView的scaleType属性

    这篇随笔将会简单的记录下ImageView这个控件的一些使用方法,以及其最重要的一个属性: scaleType ImageView这个控件是用来显示图片用的,例如我们可以通过下面这段xml配置来声明显示一张图片: <ImageView n...

    图片自适应大小1

    网络上下载下来的图片自适应:android:adjustViewBounds="true"(其详细解释在下面)<ImageView android:id=

    android LabelView 自定义各种效果的 label 控件

    <cn.label.avatarlabelview.LabelImageView app:textContent="晚场" app:textContentSize="14sp" app:direction="rightTop" app:labelTopDistance="20dp" app:labelTopPadding="10dp" app:labelBottomPadding=...

    Android实验指导.doc

    " "android:layout_width="fill_parent" " "android:layout_height="wrap_content" " "/> " "<ImageView android:id="+id/ImageView01" " "android:layout_width="wrap_content" " "android:layout_height="wrap_...

    安卓在系统控件中加入自定义属性

    安卓如何在系统控件中加入自定义属性 <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="20dp" android:layout_gravity="center" android:src="@...

    如何让安卓(Android)子控件超出父控件的范围显示

    先来看一张预览图:   废话不多说,直接上代码: <RelativeLayout xmlns:android=...ImageView android:layout_width=match_parent android:layout_height=match_parent an

Global site tag (gtag.js) - Google Analytics