Android Drawable Resources系列9:
16lz
2021-01-23
定义:图片缩放,基于level来控制其显示。
用法:
<?xml version="1.0" encoding="utf-8"?><scale xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/drawable_resource" android:scaleGravity=["top" | "bottom" | "left" | "right" | "center_vertical" | "fill_vertical" | "center_horizontal" | "fill_horizontal" | "center" | "fill" | "clip_vertical" | "clip_horizontal"] android:scaleHeight="percentage" android:scaleWidth="percentage" />
属性 | 作用 |
android:drawable | 图片资源 |
android:scaleGravity | 缩放中心,就是向什么方位上缩放 |
android:scaleHeight | 值:XX%:12.5%,20%。缩放比例,20%就是缩放20%,剩下80% |
android:scaleWidth | 值:XX%:12.5%,20%。缩放比例,20%就是缩放20%,剩下80% |
效果:
1、XML文件中resource_drawable_scale.xml:<?xml version="1.0" encoding="utf-8"?><scale xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@mipmap/reasource_drawable_mn4" android:scaleGravity="center_vertical|center_horizontal" android:scaleHeight="20%" android:scaleWidth="20%"></scale>
2、layout文件中,原始图片是同一张:
<ImageView android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:src="@mipmap/reasource_drawable_mn4" /> <ImageView android:id="@+id/img_scale" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:src="@drawable/resource_drawable_scale" />
3、Activity中,level必须大于0,否则无法显示:
img_scale = (ImageView) findViewById(R.id.img_scale); ScaleDrawable scaleDrawable = (ScaleDrawable) img_scale.getDrawable(); scaleDrawable.setLevel(1);
更多相关文章
- android上传图片至服务器
- 仿优酷Android客户端图片左右滑动(自动滑动)
- Android 使用Handler的PostDelayed方法实现图片的轮播
- Android剪切图片
- android button 上添加图片
- android 图片相关处理
- android从网上加载图片简单示例
- Android图片的处理类
- android 多点触摸实现图片缩放