简单例子:clip_drawable.xml
<?xml version="1.0" encoding="utf-8"?>
<clip xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/ic_launcher"
android:gravity="left"
android:clipOrientation="horizontal" />
xml布局文件中的加载:
<ImageView
android:id="@+id/img_clip"
android:layout_width="200dp"
android:layout_height="200dp"
android:src="@drawable/clip_drawable" />
在activity中的调用和设置:
<span style="white-space:pre"> </span>private ClipDrawable clip;
private Handler handler = new Handler(){
public void handleMessage(android.os.Message msg) {
clip.setLevel(msg.what);
};
};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView image = (ImageView) findViewById(R.id.img_clip);
clip = (ClipDrawable) image.getDrawable();
new Thread(run).start();
}
Runnable run = new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
for(int i = 0; i < 10000; i += 100){
handler.sendEmptyMessage(i);
try{
Thread.sleep(200);
}catch(Exception e){
}
}
}
};
ClipDrawable 的进度为 0-10,000 ,10K的时候为满值