android ClipDrawable实现进度条

来源:互联网 发布:清除的数据怎么恢复 编辑:程序博客网 时间:2024/05/17 05:18

1、

在drawable 下创建一个<clip>标签的布局 progress.xml 如下

<?xml version="1.0" encoding="utf-8"?>
<clip xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/pro"
    android:clipOrientation="horizontal"
    android:gravity="left" >
  
</clip>

android:drawable 引用的图片资源

android:clipOrientation 控制裁剪的方向可以是horizontal 或者vertical 

android:gravity控制裁剪从哪里开始 这里表示从左开始


2、在布局文件中应用 eg:


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

 <ImageView
        android:id="@+id/iv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
         android:src="@drawable/progress"
        />


</RelativeLayout>


3.关键代码

private ImageView imageView;
  
private ClipDrawable  clipDrawable;

private   int  progress= 0

 
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
imageView =(ImageView) findViewById(R.id.iv);
clipDrawable= (ClipDrawable) imageView.getDrawable();

clipDrawable.setLevel(2000);

}

      imageLevel 最大10000,默认是从0开始  在此可控制这个来实现进度条的变化



原创粉丝点击