Android ImageView(插入图片)属性详解
2023-09-14 09:04:24 时间
效果图:
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_nature"/>
</RelativeLayout>
常用属性总结:
android:src //设置显示的图片,导入格式为:文件夹名/图片名,例如: @drawable/ic_nature
android:scaleType //调整图片缩放、位置等以满足ImageView显示的需要
ScaleType.CENTER::图片大小为原始大小,如果图片大小大于ImageView控件,则截取图片中间部分,若小于,则直接将图片居中显示。
ScaleType.CENTER_CROP:将图片等比例缩放,让图像的短边与ImageView的边长度相同,即不能留有空白,缩放后截取中间部分进行显示。
ScaleType.CENTER_INSIDE:将图片大小大于ImageView的图片进行等比例缩小,直到整幅图能够居中显示在ImageView中,小于ImageView的图片不变,直接居中显示。
ScaleType.FIT_CENTER:ImageView的默认状态,大图等比例缩小,使整幅图能够居中显示在ImageView中,小图等比例放大,同样要整体居中显示在ImageView中。
ScaleType.FIT_END:缩放方式同FIT_CENTER,只是将图片显示在右方或下方,而不是居中。
ScaleType.FIT_START:缩放方式同FIT_CENTER,只是将图片显示在左方或上方,而不是居中。
ScaleType.FIT_XY:将图片非等比例缩放到大小与ImageView相同。
ScaleType.MATRIX:是根据一个3x3的矩阵对其中图片进行缩放
相关文章
- Android开发之ImageView ScaleType属性
- [Android Pro] Fragment中使用SurfaceView切换时闪一下黑屏的解决办法
- [Android UI] ProgressBar自定义
- 105、android:windowSoftInputMode属性详解
- Android 动画的分类
- android 属性动画
- 49、android ListView几个比较特别的属性
- 《Android Jetpack》— Android 书籍
- 【Android笔记48】Android中几个常见的类(DisplayMetrics、WindowManager、LayoutInflater、LayoutParams)
- Android 11.0 动态修改SystemProperties中ro开头系统属性的值
- Android 10.0 系统settings系统属性控制一级菜单显示隐藏
- Android 10.0 User版本通过属性来开启或关闭root权限
- Android 动画之属性动画详解
- android EditText特殊属性详解
- Android 属性动画简单分析(二)
- 【Android Gradle 插件】Gradle 扩展属性 ② ( 定义在根目录 build.gradle 中的扩展属性 | 使用 rootProject.扩展属性名访问 | 扩展属性示例 )
- 【Android Gradle 插件】TestOptions 配置 ① ( BaseExtension#testOptions 配置 | TestOptions 配置简介 )
- 【Android Gradle 插件】LintOptions 配置 ⑩ ( textReport 属性配置 | textOutput 属性配置 | warningsAsErrors 属性配置 )
- 【Android 逆向】类加载器 ClassLoader ( 类加载时机 | 隐式加载 | 显示加载 | 类加载步骤 | 装载 | 链接 | 初始化 )
- 【Android 逆向】Android 权限 ( ro.product.cpu.abi 属性 | ro.zygote 属性 | dhcp.eth0 属性 | net.* 属性 )
- 浅谈Android进阶之路
- Android相关属性的介绍:android:exported = true
- android:ellipsize属性的含义
- ImageView的android:scaleType各属性含义(zz)
- Android 从底部弹出三级(省市区)选择器
- Android开发问题集锦八--基于VLC的RTSP拉流测评
- Android录音采样率限制问题(十一)
- Android dalvik GC相关的属性详解