日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

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

發布時間:2023/12/10 Android 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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);

?

總結

以上是生活随笔為你收集整理的Android 自定义操作成功的loading动画的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。