下面请先看效果图:
看上去是不很炫的样子,它的实现上也不是很复杂,重点在与onDraw()方法的绘制。
首先是我们的attrs文件:
接下来是我们重写View类的自定义View类:
public class MySelfCircleView extends View {
int firstColor;
int secondColor;
int circleWidth;
int speed;
Paint mPaint;
int mProgress;
boolean isNext;
public MySelfCircleView(Context context, AttributeSet attrs,
int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CustomView, defStyleAttr, 0);
int n = typedArray.getIndexCount();
for(int i=0; i
最后是我们的布局文件:
总结
好了,到这里我们的效果就算大工告成,感兴趣的朋友可以写写看,个人感觉自定义View需要大量的练习,才能为我所用。希望本文对大家开发Android能有所帮助。



