转载请注明出处:王亟亟的大牛之路
最近看了一大堆的自定义View多数都可以充当耗时操作的交互界面,再接再厉再传一个SubmitView,一个和可用于模仿提交等待与用户交互用的一个自定义View
效果图:
项目结构:
一个Android Studio项目。也可以转成Eclipse,因为没有涉及到打包啊lib的一些操作,连资源文件都没用,所以可以直接Copy过去。
自定义View
public class SubmitView extends View {
private static final int COLOR_BACK = 0xff00cd97;
private static final int COLOR_GREY = 0xffb9b9b9;
private int mColor = COLOR_BACK;
//
private Paint mBorderPaint;
private Paint mTextPaint;
private Paint mBackPaint;
private int mWidth;
private int mHeight;
private int mRadius;
private static final int PADDING = 5;
private Rect mTextBounds;
private boolean mShowText = true;
private static final String TEXT_SUBMIT = "提交";
private String mText = TEXT_SUBMIT;
private int mStrokeWidth;
// indicate if view can click
private boolean mCanClick = true;
// indicate the animator state
private AniState mAniState = AniState.INIT;
private boolean mIfReset = false;
enum AniState {
INIT,
FIRST_START, // start animation which change backcolor and text color
FIRST_STOP,
SECOND_START, // second animation which change "submit" size for a while
SECOND_STOP,
THIRD_START, // third animation which convert to circle and change back color
THIRD_STOP,
FOURTH_START, // fourth animation which show the progress
FOURTH_STOP,
FIFTH_START, // fifth animation which can narrow the back and border and show "correct" sign
FIFTH_STOP;
public boolean isPlaying() {
return this==FIRST_START
|| this==SECOND_START
|| this == THIRD_START
|| this == FOURTH_START
|| this == FIFTH_START;
}
@Override
public String toString() {
switch (this) {
case INIT:
return "***init***";
case FIRST_START:
return "***first start***";
case FIRST_STOP:
return "***first stop***";
case SECOND_START:
return "***second start***";
case SECOND_STOP:
return "***second stop***";
case THIRD_START:
return "***third start***";
case THIRD_STOP:
return "****third stop**";
case FOURTH_START:
return "***fourth start***";
case FOURTH_STOP:
return "***fourth stop***";
case FIFTH_START:
return "***fifth start***";
case FIFTH_STOP:
return "***fifth stop";
default:
return "unknown state";
}
}
}
public SubmitView(Context context) {
this(context, null, 0);
}
public SubmitView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public SubmitView(Context context, Attribute