ClipDrawable,能够剪切图片,经常使用于进度条。 android
xml文件中的格式: spa
<?xml version="1.0" encoding="utf-8"?>
<clip
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/drawable_resource"
android:clipOrientation=["horizontal" | "vertical"]
android:gravity=["top" | "bottom" | "left" | "right" | "center_vertical" | "fill_vertical" | "center_horizontal" | "fill_horizontal" | "center" | "fill" | "clip_vertical" | "clip_horizontal"] />
xml
android:clipOrientation属性:指明了剪切的方向
android:gravity属性:指明了剪切的开始位置。
例如:top,则从Drawable下部开始剪切。left,则从Drawable右部开始剪切。
使用代码:
ImageView imageview = (ImageView) findViewById(R.id.image);
ClipDrawable drawable = (ClipDrawable) imageview.getDrawable();
drawable.setLevel(drawable.getLevel() + 1000);
其中setLevel的值从0到10000。0表示100%剪切,10000表示%0剪切。 图片