推荐安卓开发神器(里面有各种UI特效和android代码库实例)
正文
一、结构
java.lang.Object
android.widget.ImageView
已知直接子类:
ImageButton, QuickContactBadge
已知间接子类:
ZoomButton
二、类概述
显示任意图像,例如图标。ImageView类可以加载各种来源的图片(如资源或图片库),需要计算图像的尺寸,比便它可以在其他布局中使用,并提供例如缩放和着色(渲染)各种显示选项。
三、XML属性
属性名称 |
描述 |
|||||||||||||||||||||||||||
android:adjustViewBounds |
是否保持宽高比。需要与maxWidth、MaxHeight一起使用,否则单独使用没有效果。 |
|||||||||||||||||||||||||||
android:cropToPadding |
是否截取指定区域用空白代替。单独设置无效果,需要与scrollY一起使用,效果如下,实现代码见代码部分:
|
|||||||||||||||||||||||||||
android:maxHeight |
设置View的最大高度,单独使用无效,需要与setAdjustViewBounds一起使用。如果想设置图片固定大小,又想保持图片宽高比,需要如下设置: 1) 设置setAdjustViewBounds为true; 2) 设置maxWidth、MaxHeight; 3) 设置设置layout_width和layout_height为wrap_content。 |
|||||||||||||||||||||||||||
android:maxWidth |
设置View的最大宽度。同上。 |
|||||||||||||||||||||||||||
android:scaleType |
设置图片的填充方式。
|
|||||||||||||||||||||||||||
android:src |
设置View的drawable(如图片,也可以是颜色,但是需要指定View的大小) |
|||||||||||||||||||||||||||
android:tint |
将图片渲染成指定的颜色。见下图: 左边为原图,右边为设置后的效果,见后面代码。 |
四、代码
4.1 android:tint
<ImageView android:background="@android:color/white" android:src="@drawable/btn_mode_switch_bg" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView> <ImageView android:layout_marginLeft="5dp" android:background="@android:color/white" android:tint="#ffff00" android:src="@drawable/btn_mode_switch_bg" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>4.2 android:cropToPadding
<ImageView android:background="@android:color/white" android:scrollY="-10px" android:cropToPadding="true" android:src="@drawable/btn_mode_switch_bg" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView> <ImageView android:background="@android:color/white" android:scrollY="10px" android:cropToPadding="true" android:src="@drawable/btn_mode_switch_bg" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView> <ImageView android:paddingTop="10px" android:background="@android:color/white" android:scrollY="10px" android:cropToPadding="true" android:src="@drawable/btn_mode_switch_bg" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView> <ImageView android:paddingTop="10px" android:background="@android:color/white" android:scrollY="10px" android:cropToPadding="false" android:src="@drawable/btn_mode_switch_bg" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
相关推荐
NULL 博文链接:https://sunzone.iteye.com/blog/1869915
图片说明Andorid中ImageView的不同属性ScaleType的区别
ImageView基础属性详解 详见博文http://blog.csdn.net/a87b01c14/article/details/49615689
注意TextView默认是透明的,不用写此属性,但是Buttom/ImageButton /ImageView想透明的话就得写这个属性了。 android:clickable 是否响应点击事件。 android:contentDescription 设置View的备注说明,作为一种辅助...
ImageView是用于界面上显示图片的控件。这篇文章主要介绍了Android ImgView属性图文详解,需要的朋友参考下
属性动画(Animator):通过操纵一个属性的get/set方法,真实地改变目标的某些属性。 传统动画框架的局限性 既然有了传统动画框架,Google 为什么还要创造一个属性动画框架呢? 我们下面举个例子来说明一下传统动画...
ImageView中XML属性src和background的区别: background会根据ImageView组件给定的长宽进行拉伸,而src就存放的是原图的大小,不会进行拉伸。src是图片内容(前景),bg是背景,可以同时使用。 此外:scaleType只对...
6.5 案例1:圆形ImageView组件 186 6.6 案例2:验证码组件CodeView 190 6.7 练习作业 202 第七章 自定义容器 204 7.1 概述 204 7.2 ViewGroup类 205 7.2.1 ViewGroup常用方法 205 7.2.2 ViewGroup的工作原理 208 ...
Android自定义控件属性详细介绍 1. reference:参考某一资源ID。 (1)属性定义: (2)属性使用: <ImageView android:layout_width = 42dip android:layout_height = 42dip
对应博客讲解地址:android自定义控件_深度解析自定义属性 http://blog.csdn.net/yezhuAndroid/article/details/79418570
ImageView的边框 图片切换查看 Android开发培训课件.ppt android ListView详解.doc Android 中几个常用属性的设置.doc android 读取文件内容操作.doc Android 选项卡效果.doc Android中 信息的输出——Log.v...
ImageView的边框 图片切换查看 Android开发培训课件.ppt android ListView详解.doc Android 中几个常用属性的设置.doc android 读取文件内容操作.doc Android 选项卡效果.doc Android中 信息的输出——Log.v的使用....
这个类是继承自ImageView的,所以对于这个控件我们可以使用ImageView的所有属性 二、使用准备, 在as 的 build.grade文件中写上 compile 'com.android.support:design:22.2.0' 三、使用说明 <android.support....
Android lint工具是Android studio中集成的一个代码提示工具,它主要负责对你的代码进行优化提示,包括xml和java文件,很...代码提示我们在6行需要为ImageView添加ContentDescription属性,突然感觉好强大。 其实我们
Android+的一些特效,这些特效代码有:Android中的ImageView边框、Android开发培训课件.ppt、android ListView详解.doc、android 读取文件内容操作.doc、Android 选项卡效果.doc、Android 中几个常用属性的设置
我们知道,TextView控件一般是用来显示文本的,而图片一般是用ImageView控件来显示。 那TextView能否显示图片呢?答案是肯定的!下面列出常见的4种方式。 1、XML文件中指定属性值 这种方式应该是最常用的了,在...
5.1.1 图片视图(ImageView) 5.1.2 滚动视图(ScrollView) 5.1.3 网格视图(GridView) 5.1.4 列表视图(ListView) 5.1.5 切换图片(ImageSwitcher和Gallery) 5.1.6 标签切换(Tab) 5.2 通用XML属性 第6章 ...
UIButton内部默认有个UIImageView、UILabel控件,可以分别用下面属性访问: 代码如下: @property(nonatomic,readonly,retain) UIImageView *imageView; @property(nonatomic,readonly,retain) UILabel *titleLabel...