定义:图片缩放,基于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);





更多相关文章

  1. android上传图片至服务器
  2. 仿优酷Android客户端图片左右滑动(自动滑动)
  3. Android 使用Handler的PostDelayed方法实现图片的轮播
  4. Android剪切图片
  5. android button 上添加图片
  6. android 图片相关处理
  7. android从网上加载图片简单示例
  8. Android图片的处理类
  9. android 多点触摸实现图片缩放

随机推荐

  1. 关于greenDao函数报错
  2. Android—自制Android闹钟3步即可!(2020-6
  3. android 获取实时麦克风声音大小
  4. 《Android第一行代码》first reading 十
  5. Android(安卓)7.0 系统解决拍照的问题 ex
  6. Android Broadcast 用法简单讨论
  7. android studio 使用adb 命令传递文件到a
  8. android 一些常用控件属性设置
  9. Android自定义对话框的使用
  10. Android 进阶—— Android 系统安全机制