Android 自定义操作成功的loading动画

1、res---->values文件夹下添加文件attrs.xml详情如下:

<?xml version="1.0" encoding="utf-8"?>
<resources><declare-styleable name="SuccessView"><attr name="svStrokeColor" format="color|reference" /><attr name="svStrokeWidth" format="float" /></declare-styleable></resources>

2、自定义操作成功动画

/*** 作者:created by meixi* 邮箱:13164716840@163.com* 日期:2018/9/6 09*/
public class MySuccessView extends View {private float mDensity = -1;private Paint mPaint, nPaint;private float minWidth;//动画大小private float minHeight;private float angle, startAngle = -90;private final float CONST_RADIUS = dip2px(1.2f);private final float CONST_RECT_WEIGHT = dip2px(3);private final float CONST_LEFT_RECT_W = dip2px(15);private final float CONST_RIGHT_RECT_W = dip2px(25);private float mLeftRectWidth = 0;private float mRightRectWidth = 0;public MySuccessView(Context context) {this(context, null);}public MySuccessView(Context context, AttributeSet attrs) {this(context, attrs, 0);}public MySuccessView(Context context, AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);init(attrs);}private void init(AttributeSet attrs) {TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.SuccessView);int pColor = typedArray.getColor(R.styleable.SuccessView_svStrokeColor, 0xffA5DC86);float strokeWidth = typedArray.getFloat(R.styleable.SuccessView_svStrokeWidth, 2.5f);typedArray.recycle(); //should recycleminWidth = dip2px(50);minHeight = dip2px(50);mPaint = new Paint();mPaint.setColor(pColor);mPaint.setStyle(Paint.Style.FILL_AND_STROKE);mPaint.setStrokeWidth(0.8f);mPaint.setAntiAlias(true);nPaint = new Paint();nPaint.setAntiAlias(true);nPaint.setStyle(Paint.Style.STROKE);nPaint.setStrokeWidth(dip2px(strokeWidth));nPaint.setColor(pColor);}@Overrideprotected void onDraw(Canvas canvas) {Rect bounds = canvas.getClipBounds();float left, right, top, bottom;if (bounds.width() > bounds.height()) {float distance = (bounds.width() / 2 - bounds.height() / 2);left = bounds.left + distance;right = bounds.right - distance;top = bounds.top;bottom = bounds.bottom;} else if (bounds.width() < bounds.height()) {float distance = (bounds.height() / 2 - bounds.width() / 2);top = bounds.top + distance;bottom = bounds.bottom - distance;left = bounds.left;right = bounds.right;} else {left = bounds.left;right = bounds.right;top = bounds.top;bottom = bounds.bottom;}RectF oval = new RectF(left + dip2px(2f), top + dip2px(2f), right - dip2px(2f), bottom - dip2px(2f));canvas.drawArc(oval, startAngle, angle, false, nPaint);int totalW = getWidth();int totalH = getHeight();canvas.rotate(45, totalW / 2, totalH / 2);totalW /= 1.2;totalH /= 1.4;RectF leftRect = new RectF();if (mLeftRectWidth > 0) {leftRect.left = (totalW - CONST_LEFT_RECT_W) / 2 + CONST_RECT_WEIGHT;leftRect.right = leftRect.left + dip2px(mLeftRectWidth);leftRect.top = (totalH + CONST_RIGHT_RECT_W) / 2;leftRect.bottom = leftRect.top + CONST_RECT_WEIGHT;canvas.drawRoundRect(leftRect, CONST_RADIUS, CONST_RADIUS, mPaint);}if (mRightRectWidth > 0) {RectF rightRect = new RectF();rightRect.bottom = (totalH + CONST_RIGHT_RECT_W) / 2 + CONST_RECT_WEIGHT - 1;rightRect.left = (totalW + CONST_LEFT_RECT_W) / 2;rightRect.right = rightRect.left + CONST_RECT_WEIGHT;rightRect.top = rightRect.bottom - dip2px(mRightRectWidth);canvas.drawRoundRect(rightRect, CONST_RADIUS, CONST_RADIUS, mPaint);}super.onDraw(canvas);}@Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {int widthMode = MeasureSpec.getMode(widthMeasureSpec);int widthSize = MeasureSpec.getSize(widthMeasureSpec);int heightMode = MeasureSpec.getMode(heightMeasureSpec);int heightSize = MeasureSpec.getSize(heightMeasureSpec);int width;int height;if (widthMode == MeasureSpec.EXACTLY) {width = widthSize;} else {width = (int) (getPaddingLeft() + minWidth + getPaddingRight());}if (heightMode == MeasureSpec.EXACTLY) {height = heightSize;} else {height = (int) (getPaddingTop() + minHeight + getPaddingBottom());}setMeasuredDimension(width, height);}public float dip2px(float dpValue) {if (mDensity == -1) {mDensity = getResources().getDisplayMetrics().density;}return dpValue * mDensity + 0.5f;}public void startAnim(int startDelay) {clearAnimation();ValueAnimator animator = ValueAnimator.ofFloat(0, 60f, 120f, 180f, 240f, 300f, 360f, 375f, 400f);animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {@Overridepublic void onAnimationUpdate(ValueAnimator valueAnimator) {float value = (float) valueAnimator.getAnimatedValue();angle = -value;if (value>360 && value<=375){mLeftRectWidth = value - 360;}else if(value>375){mRightRectWidth = value - 375;}invalidate();}});animator.setDuration(1000);animator.setInterpolator(new LinearInterpolator());animator.setStartDelay(startDelay);animator.start();}
}3、activity调用

3、activity 调用自定义操作成功动画

 

<com.administrator.tests.MySuccessViewandroid:id="@+id/view"android:layout_width="wrap_content"android:layout_height="wrap_content"app:svStrokeColor="@color/colorPrimary" />
MySuccessView sv =(MySuccessView)findViewById(R.id.view) ;
sv.startAnim(200);

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/415249.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

cesium的clock开始,结束,控制速率

开始 viewer.clock.shouldAnimate true; 结束 window.viewer.clock.shouldAnimate false;速率调整 viewer.clock.multiplier 8;

Android 下载进度条, 自定义加载进度条,loading动画

1、自定义loadingline动画 /*** 作者&#xff1a;created by meixi* 邮箱&#xff1a;13164716840163.com* 日期&#xff1a;2018/9/6 10*/public class LoadingLine extends View {private Paint paint;private Paint backPaint;private Paint textPaint;private boolean ini…

eslint airbnb 不允许尾随逗号

我使用的是airbnb规则进行代码eslint。 会出现保存后&#xff0c;数组或者对象最后一个元素尾随逗号。 此时需要在.eslintrc.js中加入下面代码即可 "comma-dangle": ["error", {"arrays": "never","objects": "never…

我的物联网项目(十二) 单体应用架构不行?

单体应用架构在创业型项目里面是非常合适的&#xff0c;毕竟它主要的担当还是在验证创业模式以及迅速功能实现&#xff0c;所以它从开发到部署&#xff0c;在少量开发人员的基础上能非常减少成本&#xff0c;主要是门槛低&#xff0c;开发效率也非常高。到目前为此&#xff0c;…

Android listview优化以及listview混合itemview

listView (ListView) findViewById(R.id.listview); mAdapter new VideoListAdapter(this); listView.setAdapter(mAdapter); 主要adapter public class VideoListAdapter extends BaseAdapter {int[] viewtype {0, 0, 0, 1, 0, 0, 0, 1, 0, 0};//1 jcvd, 0 textView。主要…

vue项目中assets与static的区别

在使用vue脚手架生成的目录中&#xff0c;会有一个src/assets还有一个static。 两者都可以用来放一些静态文件。那有什么区别呢&#xff1f; static中的文件不会被webpack打包&#xff0c;文件被复制到dist/static assets中的文件会经过 webpack 打包&#xff0c;重新编译。…

oracle 用户管理

一、创建用户概述&#xff1a;在oracle中要创建一个新的用户使用create user语句&#xff0c;一般是具有dba(数据库管理员)的权限才能使用。create user 用户名 identified by 密码; 注意&#xff1a;oracle有个毛病&#xff0c;密码必须以字母开头&#xff0c;如果以数字开头&…

Android 获取当前的时间。年月日,时分秒,星期几

SimpleDateFormat alldate new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//获取日期时间 SimpleDateFormat year new SimpleDateFormat("yyyy");//获取年份SimpleDateFormat month new SimpleDateFormat("MM");//获取月份SimpleDateFormat m…

mac通过homebrew安装opensdk11

1、安装cask brew tap homebrew/cask-versions 2、安装adoptopenjdk/openjdk brew tap adoptopenjdk/openjdk 3、查看一下java、jdk版本 brew search java brew search jdk 4、安装adoptopenjdk11 brew cask info adoptopenjdk11 brew cask install adoptopenjdk11…

缺失值侦测与处理

缺失值的侦测的方法&#xff1a; 1、mice包中的md.pattern()函数可以生成一个以矩阵或数据框形式展示缺失值模式的表格 这个矩阵呢&#xff0c;表示像第一行缺失0个的模式有13行&#xff0c;像第二行缺失1个的模式有1行&#xff0c;如此类推 所以呢&#xff0c;一共就有0*131*1…

工作172:自己工作开始封装的一个小组件

其实很简单 <!--封装部门选择的插件 需要的组件 子组件--> <template><el-select :value"value" placeholder"请选择所属部门" change"handleChange"><el-optionv-for"department in departments":key"de…

高德地图 amap 设置鼠标样式

我的需求&#xff0c;要在高德地图里面做一个地图选点的功能。这个功能很简单&#xff0c;但是高德地图的默认鼠标样式是一只小手&#xff0c;不适合做选点用。 高德地图中有4中样式如下图 对应名称如下&#xff1a; pointer&#xff0c;default&#xff0c;move&#xff0c…

Android 设置定时刷新页面数据,最小自动刷新时间

设置初始时间 SimpleDateFormat df new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式 String thistime df.format(new Date());SharedPreferences sharedPreferences getSharedPreferences("industryInfo", Context.MODE_PRIVATE); //私有…

eslint 设置全局 变量

我在做高德地图开发的时候&#xff0c;喜欢将map作为全局变量&#xff0c;但是eslint会显示报红。 所以需要在.eslintrc.js中加上如下配置&#xff1a; "globals": {"map": true}

Android 自定义软键盘实现

module链接&#xff1a;https://download.csdn.net/download/meixi_android/10652565 compile project(:edlibrary) , :edlibrary <?xml version"1.0" encoding"utf-8"?> <LinearLayout xmlns:android"http://schemas.android.com/apk/…

微信小程序自定义组件生命周期

created 组件实例化&#xff0c;但节点树还未导入&#xff0c;因此这时不能用setData attached 节点树完成&#xff0c;可以用setData渲染节点&#xff0c;但无法操作节点 ready (不是onReady) 组件布局完成&#xff0c;这时可以获取节点信息&#xff0c;也可以操作节点 mov…