热门标签 | HotTags
当前位置:  开发笔记 > Android > 正文

animation-circleProgress_html/css_WEB-ITnose

animation-circleProgress
CircleProgress
github上一个开源项目
代码的主要目录是这样
1. CircleProgress
2. EaseInOutCubicInterpolator
3. MainActivity
MainActivity是主界面负责布局的初始化和动画的启动暂停等控制
EaseInOutCubicInterpolator是时间插值生成的类
下面附上加了注释的代码:

package me.fichardu.circleprogress;import android.animation.TimeInterpolator;import android.content.Context;import android.content.res.TypedArray;import android.graphics.Canvas;import android.graphics.Paint;import android.graphics.Point;import android.util.AttributeSet;import android.util.Log;import android.view.View;import android.view.animation.AnimationUtils;public class CircleProgress extends View {    private static final int RED = 0xFFE5282C;    private static final int YELLOW = 0xFF1F909A;    private static final int BLUE = 0xFFFC9E12;    private static final int COLOR_NUM = 3;    private int[] COLORS;    private TimeInterpolator mInterpolator = new EaseInOutCubicInterpolator();    private final double DEGREE = Math.PI / 180;    private Paint mPaint;    private int mViewSize;    private int mPointRadius;    private long mStartTime;    private long mPlayTime;    private boolean mStartAnim = false;    private Point mCenter = new Point();    private ArcPoint[] mArcPoint;    private static final int POINT_NUM = 15;    private static final int DELTA_ANGLE = 360 / POINT_NUM;    private long mDuration = 3600;    public CircleProgress(Context context) {        super(context);        //构造函数初始化时开始初始化View        init(null, 0);    }    public CircleProgress(Context context, AttributeSet attrs) {        super(context, attrs);        init(attrs, 0);    }    public CircleProgress(Context context, AttributeSet attrs, int defStyle) {        super(context, attrs, defStyle);        init(attrs, defStyle);    }    private void init(AttributeSet attrs, int defStyle) {        //初始化存放15个点的数组        mArcPoint = new ArcPoint[POINT_NUM];        //构建画布并设置画布的属性        mPaint = new Paint();        //加上抗锯齿        mPaint.setAntiAlias(true);        //画的点为实心点        mPaint.setStyle(Paint.Style.FILL);        //自定义属性,这里主要是为了给点上色,似乎不适用自定义颜色也可以        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.CircleProgress, defStyle, 0);        int color1 = a.getColor(R.styleable.CircleProgress_color1, RED);        int color2 = a.getColor(R.styleable.CircleProgress_color2, YELLOW);        int color3 = a.getColor(R.styleable.CircleProgress_color3, BLUE);        a.recycle();        COLORS = new int[]{color1, color2, color3};    }    @Override    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {        //当View被初始化被调用来获取view的大小        int defaultSize = getResources().getDimensionPixelSize(R.dimen.default_circle_view_size);        int width = getDefaultSize(defaultSize, widthMeasureSpec);        int height = getDefaultSize(defaultSize, heightMeasureSpec);        //在这里取一个长宽最小的size        mViewSize = Math.min(width, height);        //取一个正方形        setMeasuredDimension(mViewSize, mViewSize);        //设置中心点,在ondraw里面进行绘制        mCenter.set(mViewSize / 2, mViewSize / 2);        //view初始化好后开始画点        calPoints(1.0f);    }    @Override    protected void onDraw(Canvas canvas) {        //view初始化好后开始调用onDraw,所以Ondraw是在onMeasure之后被调用        //canvas.save()保存之前的状态,保存之后再进行包括平移旋转等的绘制        canvas.save();        //移动坐标原点        canvas.translate(mCenter.x, mCenter.y);        //获取时间因子        float factor = getFactor();        //按照计算好的因子进行旋转        canvas.rotate(36 * factor);        float x, y;        //通过插值getItemFactor重新计算点的位置        for (int i = 0; i  1f) {            itemFactor = 1f;        }        return mInterpolator.getInterpolation(itemFactor);    }    public void startAnim() {        mPlayTime = mPlayTime % mDuration;        mStartTime = AnimationUtils.currentAnimationTimeMillis() - mPlayTime;        mStartAnim = true;        postInvalidate();    }    public void reset() {        stopAnim();        mPlayTime = 0;        postInvalidate();    }    public void stopAnim() {        mStartAnim = false;    }    public void setInterpolator(TimeInterpolator interpolator) {        mInterpolator = interpolator;    }    public void setDuration(long duration) {        mDuration = duration;    }    public void setRadius(float factor) {        stopAnim();        calPoints(factor);        startAnim();    }    static class ArcPoint {        float x;        float y;        int color;        ArcPoint(float x, float y, int color) {            this.x = x;            this.y = y;            this.color = color;        }    }}
package me.fichardu.circleprogress;import android.animation.TimeInterpolator;/** * The MIT License (MIT) * * Copyright (c) 2015 fichardu * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */public class EaseInOutCubicInterpolator implements TimeInterpolator {    @Override    public float getInterpolation(float input) {        if ((input *= 2) <1.0f) {            //轨迹方程 0.5*x^3            return 0.5f * input * input * input;        }        input -= 2;        //轨迹方程0.5*x^3+1        return 0.5f * input * input * input + 1;    }}

主activity比较简单就不加注释了

package me.fichardu.circleprogress;import android.os.Bundle;import android.support.v7.app.ActionBarActivity;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.widget.SeekBar;public class MainActivity extends ActionBarActivity implements View.OnClickListener {    private CircleProgress mProgressView;    private View mStartBtn;    private View mStopBtn;    private View mResetBtn;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        mProgressView = (CircleProgress) findViewById(R.id.progress);        mProgressView.startAnim();        mStartBtn = findViewById(R.id.start_btn);        mStartBtn.setOnClickListener(this);        mStopBtn = findViewById(R.id.stop_btn);        mStopBtn.setOnClickListener(this);        mResetBtn = findViewById(R.id.reset_btn);        mResetBtn.setOnClickListener(this);        SeekBar mSeekBar = (SeekBar) findViewById(R.id.out_seek);        mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {            @Override            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {            }            @Override            public void onStartTrackingTouch(SeekBar seekBar) {            }            @Override            public void onStopTrackingTouch(SeekBar seekBar) {                float factor = seekBar.getProgress() / 100f;                mProgressView.setRadius(factor);            }        });    }    @Override    public boolean onCreateOptionsMenu(Menu menu) {        // Inflate the menu; this adds items to the action bar if it is present.        getMenuInflater().inflate(R.menu.menu_main, menu);        return true;    }    @Override    public boolean onOptionsItemSelected(MenuItem item) {        // Handle action bar item clicks here. The action bar will        // automatically handle clicks on the Home/Up button, so long        // as you specify a parent activity in AndroidManifest.xml.        int id = item.getItemId();        //noinspection SimplifiableIfStatement        if (id == R.id.action_settings) {            return true;        }        return super.onOptionsItemSelected(item);    }    @Override    public void onClick(View v) {        if (v == mStartBtn) {            mProgressView.startAnim();        } else if (v == mStopBtn) {            mProgressView.stopAnim();        } else if (v == mResetBtn) {            mProgressView.reset();        }    }}

点的位置的计算是app特有的设计,插值器是一个共性的知识,是学习这个开源代码的核心。

版权声明:本文为博主原创文章,未经博主允许不得转载。

推荐阅读
  • 优化ListView性能
    本文深入探讨了如何通过多种技术手段优化ListView的性能,包括视图复用、ViewHolder模式、分批加载数据、图片优化及内存管理等。这些方法能够显著提升应用的响应速度和用户体验。 ... [详细]
  • 本文详细介绍了Java编程语言中的核心概念和常见面试问题,包括集合类、数据结构、线程处理、Java虚拟机(JVM)、HTTP协议以及Git操作等方面的内容。通过深入分析每个主题,帮助读者更好地理解Java的关键特性和最佳实践。 ... [详细]
  • Android LED 数字字体的应用与实现
    本文介绍了一种适用于 Android 应用的 LED 数字字体(digital font),并详细描述了其在 UI 设计中的应用场景及其实现方法。这种字体常用于视频、广告倒计时等场景,能够增强视觉效果。 ... [详细]
  • RecyclerView初步学习(一)
    RecyclerView初步学习(一)ReCyclerView提供了一种插件式的编程模式,除了提供ViewHolder缓存模式,还可以自定义动画,分割符,布局样式,相比于传统的ListVi ... [详细]
  • 深入理解OAuth认证机制
    本文介绍了OAuth认证协议的核心概念及其工作原理。OAuth是一种开放标准,旨在为第三方应用提供安全的用户资源访问授权,同时确保用户的账户信息(如用户名和密码)不会暴露给第三方。 ... [详细]
  • Android 九宫格布局详解及实现:人人网应用示例
    本文深入探讨了人人网Android应用中独特的九宫格布局设计,解析其背后的GridView实现原理,并提供详细的代码示例。这种布局方式不仅美观大方,而且在现代Android应用中较为少见,值得开发者借鉴。 ... [详细]
  • 深入解析Android自定义View面试题
    本文探讨了Android Launcher开发中自定义View的重要性,并通过一道经典的面试题,帮助开发者更好地理解自定义View的实现细节。文章不仅涵盖了基础知识,还提供了实际操作建议。 ... [详细]
  • 探讨一个显示数字的故障计算器,它支持两种操作:将当前数字乘以2或减去1。本文将详细介绍如何用最少的操作次数将初始值X转换为目标值Y。 ... [详细]
  • 解决微信电脑版无法刷朋友圈问题:使用安卓远程投屏方案
    在工作期间想要浏览微信和朋友圈却不太方便?虽然微信电脑版目前不支持直接刷朋友圈,但通过远程投屏技术,可以轻松实现在电脑上操作安卓设备的功能。 ... [详细]
  • 从零开始构建完整手机站:Vue CLI 3 实战指南(第一部分)
    本系列教程将引导您使用 Vue CLI 3 构建一个功能齐全的移动应用。我们将深入探讨项目中涉及的每一个知识点,并确保这些内容与实际工作中的需求紧密结合。 ... [详细]
  • 本文详细介绍了 Java 中 org.apache.xmlbeans.SchemaType 类的 getBaseEnumType() 方法,提供了多个代码示例,并解释了其在不同场景下的使用方法。 ... [详细]
  • 深入解析:手把手教你构建决策树算法
    本文详细介绍了机器学习中广泛应用的决策树算法,通过天气数据集的实例演示了ID3和CART算法的手动推导过程。文章长度约2000字,建议阅读时间5分钟。 ... [详细]
  • 在金融和会计领域,准确无误地填写票据和结算凭证至关重要。这些文件不仅是支付结算和现金收付的重要依据,还直接关系到交易的安全性和准确性。本文介绍了一种使用C语言实现小写金额转换为大写金额的方法,确保数据的标准化和规范化。 ... [详细]
  • 在给定的数组中,除了一个数字外,其他所有数字都是相同的。任务是找到这个唯一的不同数字。例如,findUniq([1, 1, 1, 2, 1, 1]) 返回 2,findUniq([0, 0, 0.55, 0, 0]) 返回 0.55。 ... [详细]
  • 本文探讨了卷积神经网络(CNN)中感受野的概念及其与锚框(anchor box)的关系。感受野定义了特征图上每个像素点对应的输入图像区域大小,而锚框则是在每个像素中心生成的多个不同尺寸和宽高比的边界框。两者在目标检测任务中起到关键作用。 ... [详细]
author-avatar
手机用户2602900587
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有