android 布局api文档,Android API中文文档ImageView

Android API中文文档ImageView是本文要介绍的内容,主要是来了解并学习Android API的内容,具体Android API的内容来看本文详解。

一、Android API结构

java.lang.Object

android.view.View

android.widget.ImageView

已知直接子类:

ImageButton,QuickContactBadge

已知间接子类:

ZoomButton

二、Android API类概述

显示任意图像,例如图标。ImageView类可以加载各种来源的图片(如资源或图片库),需要计算图像的尺寸,比便它可以在其他布局中使用,并提供例如缩放和着色(渲染)各种显示选项。

三、Android API中XML属性

属性名称描述

android:adjustViewBounds是否保持宽高比。需要与maxWidth、MaxHeight一起使用,否则单独使用没有效果。

android:cropToPadding是否截取指定区域用空白代替。单独设置无效果,需要与scrollY一起使用,效果如下,实现代码见代码部分:

f97706f45a0f78b4dc8ca7791b7636ed.png

android:maxHeight设置View的***高度,单独使用无效,需要与setAdjustViewBounds一起使用。如果想设置图片固定大小,又想保持图片宽高比,需要如下设置:

(1)设置setAdjustViewBounds为true;

(2)设置maxWidth、MaxHeight;

(3)设置设置layout_width和layout_height为wrap_content。

android:maxWidth设置View的***宽度。同上。

android:scaleType设置图片的填充方式。

matrix0用矩阵来绘图

fitXY1拉伸图片(不按比例)以填充View的宽高

06fa2a26b0f5dd9f898066a93705646b.png

layout_

height

:30px

layout_

width

:120px

fitStart2按比例拉伸图片,拉伸后图片的高度为View的高度,且显示在View的左边

bbdd66966d97d7f03c7084e9383a450f.png

fitCenter3按比例拉伸图片,拉伸后图片的高度为View的高度,且显示在View的中间

eceb32a60428a1e9c14e334537d388cb.png

fitEnd4按比例拉伸图片,拉伸后图片的高度为View的高度,且显示在View的右边

af201661e376fdd7b94e3b58435d68c9.png

center5按原图大小显示图片,但图片宽高大于View的宽高时,截图图片中间部分显示

5df35421dae281db973c11ea8fd02541.png

layout_

height

:60px

layout_

width

:80px

padding

:10px

centerCrop6按比例放大原图直至等于某边View的宽高显示。

ab52a5a452f9f2f039d03f5eedb9a1dc.png

centerInside7当原图宽高或等于View的宽高时,按原图大小居中显示;反之将原图缩放至View的宽高居中显示。

d3770089e610adfa115b84d4d6e45fa8.png

android:src设置View的drawable(如图片,也可以是颜色,但是需要指定View的大小)

android:tint将图片渲染成指定的颜色。见下图:

cfb0dfad57c631607084d034be420f2d.png

左边为原图,右边为设置后的效果,见后面代码。

四、Android API代码

1、android:tint

android:layout_width="wrap_content"android:layout_height="wrap_content">

android:tint="#ffff00"android:src="@drawable/btn_mode_switch_bg"

android:layout_width="wrap_content"android:layout_height="wrap_content">

2、android:cropToPadding

android:scrollY="-10px"

android:cropToPadding="true"

android:src="@drawable/btn_mode_switch_bg"

android:layout_width="wrap_content"android:layout_height="wrap_content">

android:cropToPadding="true"android:src="@drawable/btn_mode_switch_bg"

android:layout_width="wrap_content"android:layout_height="wrap_content">

android:scrollY="10px"android:cropToPadding="true"android:src="@drawable/btn_mode_switch_bg"

android:layout_width="wrap_content"android:layout_height="wrap_content">

android:scrollY="10px"android:cropToPadding="false"android:src="@drawable/btn_mode_switch_bg"

android:layout_width="wrap_content"android:layout_height="wrap_content">

小结:

Android API中文文档ImageView的内容介绍完了,希望通过Android API内容的学习能对你有所帮助!

【编辑推荐】

【责任编辑:李程站 TEL:(010)68476606】

点赞 0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值