Android 自定义View练习:风扇吹花瓣加载中loading进度条绘制

本文介绍了如何在Android平台上通过自定义View来创建一个独特的加载中指示器,该指示器以风扇吹动花瓣的形式展示加载进度。详细探讨了绘制过程和技术要点,包括自定义View的基本步骤、动画实现以及绘图API的使用。
摘要由CSDN通过智能技术生成

这里写图片描述

package com.louisgeek.louiscustomviewstudy;

import android.animation.ValueAnimator;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.os.Handler;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by louisgeek on 2016/10/21.
 */
public class LoadingCustomView05 extends View {
   
    private static final String TAG = "LoadingCustomView05";

    private static final int PROGRESSBAR_WIDTH = 550;
    /*进度条样式*/
    public static final int SOLID = 1;//实心
    public static final int SOLID_AND_FRAME = 2;//实心加边框
    public static final int HOLLOW = 3;//空心

    /***/
    private int mStartAngle_LeftArc = 90;//左边半圆或弧度的初始角度
    private int mStartAngle_RightArc_One = -90;//右边半圆或弧度上面的那部分的初始角度
    private int mStartAngle_RightArc_Two = 0;//右边半圆或弧度下面的那部分的初始角度


    private int mProgressBankgroundColor = Color.parseColor("#FA8900");
    private int mProgressColor = Color.parseColor("#98C73B");
    private float mProgress;//当前的进度
    private float mPetalDisance;
    private int mProgressBarFrameHeight = this.dp2px(8);
    private int mProgressBarBankgroundStyle = SOLID;//默认实心
    private int mProgressBarHeight = this.dp2px(20);//进度条总高度
    private int mProgressBarWidth = PROGRESSBAR_WIDTH;//进度条总长度
    //
    private boolean mHasCoordinate = false;//是否绘制参考坐标系
    //右边小圆圆环边框
    float mRightStrokeWidth = this.dp2px(5);//
    /***/
    private Paint mPaint;
    private int mViewWidth, mViewHeight;
    private int mScreenWidth, mScreenHeight;
    private boolean mHasBankground = true;//是否绘制背景
    private float mProgressMaxWidth;//进度最大宽度
    private float mProgressLoadingWidth;//当前进度条宽度

    private float mOneArcProgress;//半圆占用的最大的进度
    private float mRectWidth;//进度条中间矩形的最大宽度
    private int mProgressBarWidthWithoutFrame;
    private int mProgressBarHeightWithoutFrame;

    private float mRadius;//进度条内左右两个半圆的最大半径

    private int mDuration = 5 * 1000;//动画执行时间
    private Context mContext;


    private List<PetalBean> mPetalBeanList = new ArrayList<>();
    private int mPetalCount = 15;
    private boolean hasSinglePetal = false;
    private boolean hasInitDataed = false;
    private int again = 0;

    private int mProgressContentColor = Color.parseColor("#FE4D0E");
    ValueAnimator mValueAnimator;
    boolean mAnimatorIsStart = false;
    boolean mPosthasStart = false;

    public LoadingCustomView05(Context context) {
        this(context, null);
    }

    public LoadingCustomView05(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public LoadingCustomView05(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mContext = context;

        TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.LoadingCustomView05);
        mProgressBankgroundColor = ta.getColor(R.styleable.LoadingCustomView05_progressBankgroundColor2, mProgressBankgroundColor);
        mProgressColor = ta.getColor(R.styleable.LoadingCustomView05_progressColor2, mProgressColor);
        mProgress = ta.getFloat(R.styleable.LoadingCustomView05_progress2, mProgress);
        mProgress = mProgress / 100;//目标进度0-1
        mProgressBarFrameHeight = ta.getDimensionPixelOffset(R.styleable.LoadingCustomView05_progressBarFrameHeight2, mProgressBarFrameHeight);
        mProgressBarBankgroundStyle = ta.getInteger(R.styleable.LoadingCustomView05_progressBarBankgroundStyle2, mProgressBarBankgroundStyle);
        //
        ta.recycle();

        init();
    }

    private void init() {
        mPaint
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值