定义:图片缩放,基于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:scaleType、android:layout_alignBottom、layout_below
  2. android selector的用法
  3. 2019-12-16 Android中的动画
  4. android上传图片至服务器
  5. 仿优酷Android客户端图片左右滑动(自动滑动)
  6. Android(安卓)使用Handler的PostDelayed方法实现图片的轮播
  7. Android剪切图片
  8. android button 上添加图片
  9. android 图片相关处理

随机推荐

  1. 如何开发 native-activity 工程【详细注
  2. Android中广播优先级设置
  3. android小功能实现之拨打电话
  4. Cordova 插件 plugin.xml 文件配置
  5. 2-20 Android(安卓)简单MediaPlayer编写(
  6. android ndk中使用gprof
  7. 关于android窗口的特效
  8. android baseadapter的getview调用两次
  9. ArcGIS for Android示例解析之GP服务调用
  10. Android:Intent用法总结