使用CLIP资源制作一个进度条

来源:互联网 发布:java 单引号 转义 编辑:程序博客网 时间:2024/04/30 09:30

准备资源res/drawable/clip.xml:在progress.png上横向左切
<?xml version="1.0" encoding="utf-8"?> 
<clip xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/progress"
android:clipOrientation="horizontal"
android:gravity="left"/> 

用一个布局文件实现进度条的外形:
<?xml version="1.0" encoding="utf-8"?>  
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg">
    <ImageView
        android:id="@+id/iv_progress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/clip"/>
</LinearLayout>

使用代码剪切进度条
ImageView ivProgress=(ImageView)findViewById(R.id.iv_progress);
ClipDrawable cd=(ClipDrawable)ivProgress.getBackground();
cd.setLevel(3000);//最大值10000,此处相当于进度为30%
0 0
原创粉丝点击