progresswheel是github上面的一个开源的项目
这个是一个圆形进度条
这个也是利用github上面提供的源代码
现在开始介绍如何使用progresswheel是怎样使用的
第一步:
首先,我们需要在别人的github上面下载源代码
然后把源代码取出来
取得是
ProgressWheel这个自定义控件的源代码
把progresswheel这个源码复制到自己的工程目录底下
第二步:
下面要讲progresswheel得属性加到工程底下
在value目录底下新建一个attrs.xml文件
然后把下面的属性值添加上去
<?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="ProgressWheel"> <attr name="text" format="string" /> <attr name="textColor" format="color" /> <attr name="textSize" format="dimension" /> <attr name="barColor" format="color" /><!-- 进度条颜色 --> <attr name="rimColor" format="color" /><!-- 默认轮廓颜色 --> <attr name="rimWidth" format="dimension" /> <attr name="spinSpeed" format="dimension" /> <attr name="delayMillis" format="integer" /> <attr name="circleColor" format="color" /><!-- 圆圈内部的颜色 --> <attr name="radius" format="dimension" /> <attr name="barWidth" format="dimension" /><!-- 进度条宽度 --> <attr name="barLength" format="dimension" /><!-- 进度条长度(即进度条走过的长度) --> <attr name="contourColor" format="color"/><!-- 控制外边缘颜色 --> <attr name="contourSize" format="dimension"/> </declare-styleable> </resources>
第三步:
在布局文件上面加上命名空间,加上这个的原因是下面的控件要用到特定的属性值,所以要通过这个路径去找到,
xmlns:ProgressWheel="http://schemas.android.com/apk/res/包名"上面的方式是参考网上的,但是会出错,但是我把路径改为下面这个的时候就正确了
xmlns:ProgressWheel="http://schemas.android.com/apk/res-auto"
第四步:
声明控件
在布局文件下面,我们要声明控件,所以要调用了之前的自定义的控件
然后在加上自定义控件的一些属性
<com.example.view.ProgressWheel android:id="@+id/pw_spinner" android:layout_width="180dp" android:layout_height="180dp" android:layout_centerInParent="true" ProgressWheel:barColor="#0097D6" ProgressWheel:barLength="160dp" ProgressWheel:barWidth="15dp" ProgressWheel:rimColor="#330097D6" ProgressWheel:rimWidth="15dp" ProgressWheel:text="wait..." ProgressWheel:contourColor="#330097D6" ProgressWheel:textColor="#222"
第五步:最后我们就可以在代码中使用控件wheel = (ProgressWheel) findViewById(R.id.pw_spinner);//找到控件 wheel.setProgress(180);//设置进度 wheel.incrementProgress();//增加进度 wheel.spin();//使控件开始旋转 wheel.stopSpinning();//停止旋转
这样我们就完成了progresswheel的使用