Android加载动画系列——CircularLoadingAnim
来源:互联网 发布:无忧传奇挂机软件 编辑:程序博客网 时间:2024/06/09 15:05
Android加载动画系列——CircularLoadingAnim
小编在逛掘金社区的时候,一不小心看到了一篇讲加载动画的文章,于是点进去看了看,被这些炫酷的加载动画深深地吸引了,于是小编觉得有必要自己动手记录一下这些炫酷的动画,顺便丰富一下自己的学习笔记。
让我们先来看看效果图:
在此我就不做过多的分析,直接上源码。
1、CircularLoadingAnim.java源码如下:
public class CircularLoadingAnim extends View { private Paint mPaint; private float mWidth = 0f; private float mAnimatedValue = 0f; private int mStartAngle = 0; private float mMaxRadius = 4; RotateAnimation mProgerssRotateAnim; public CircularLoadingAnim(Context context) { this(context, null); } public CircularLoadingAnim(Context context, AttributeSet attrs) { this(context, attrs, 0); } public CircularLoadingAnim(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); initPaint(); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); if (getMeasuredWidth() > getHeight()) mWidth = getMeasuredHeight(); else mWidth = getMeasuredWidth(); mMaxRadius = mWidth / 30f; } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); for (int i = 0; i < 9; i++) { float x2 = (float) ((mWidth / 2.f - mMaxRadius) * Math.cos(mStartAngle + 45f * i * Math.PI / 180f)); float y2 = (float) ((mWidth / 2.f - mMaxRadius) * Math.sin(mStartAngle + 45f * i * Math.PI / 180f)); canvas.drawCircle(mWidth / 2.f - x2, mWidth / 2.f - y2, mMaxRadius, mPaint); } canvas.drawCircle(mWidth / 2.f, mWidth / 2.f, mWidth / 2.f - mMaxRadius * 6, mPaint); } private void initPaint() { mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setStyle(Paint.Style.FILL); mPaint.setColor(Color.WHITE); mProgerssRotateAnim = new RotateAnimation(0f, 360f, android.view.animation.Animation.RELATIVE_TO_SELF, 0.5f, android.view.animation.Animation.RELATIVE_TO_SELF, 0.5f); mProgerssRotateAnim.setRepeatCount(-1); mProgerssRotateAnim.setInterpolator(new LinearInterpolator());//不停顿 mProgerssRotateAnim.setFillAfter(true);//停在最后 } public void startAnim() { stopAnim(); mProgerssRotateAnim.setDuration(3500); startAnimation(mProgerssRotateAnim); } public void stopAnim() { clearAnimation(); }}
2、接下来就是如何使用的问题,首先我们需要在layout中引用自定义的动画控件,如下所示:
<com.cyril.loadinganim.CircularLoadingAnim android:id="@+id/circular" android:layout_width="50dp" android:layout_height="50dp" />
3、然后在相关的Activity中实现动画的播放和停止,使用事例如下:
circularLoadingAnim = (CircularLoadingAnim) findViewById(R.id.circular);circularLoadingAnim.startAnim();
4、 最后小编双手奉上源码的下载地址:http://download.csdn.net/detail/zhimingshangyan/9582830
1 0
- Android加载动画系列——CircularLoadingAnim
- Android加载动画系列——BalloonLoading
- Android加载动画系列——WaterBottleLoading
- Android加载动画系列——BatteryLoading
- Android加载动画系列——CircularCDLoadingAnim
- Android加载动画系列——CircularRingLoadingAnim
- Android加载动画系列—— CircularJumpLoadingAnim
- Android加载动画系列—— CircularSmileLoadingAnim
- Android加载动画系列——CircularZoomLoadingAnim
- Android加载动画系列—— LineWithTextLoadingAnim
- Android加载动画系列——WifiLoadingAnim
- Android加载动画系列——PlayBallLoadingAnim
- Android加载动画系列——PlayBallLoadingAnim
- Android加载动画系列——GearsLoadingAnim
- Android加载动画系列——ChromeLogoLoadingAnim
- Android加载动画系列——GearsTwoLoadingAnim
- Android加载动画系列—— GhostLoadingAnim
- Android加载动画系列——FinePoiStarLoadingAnim
- 最简单的php文件上传
- Copy、CopyFile、FileCopy的用法
- scala基础20-包使用进阶
- Android Studio导入Cordova项目
- myEclipse注册码的获取
- Android加载动画系列——CircularLoadingAnim
- poj 1988 并查集
- Objective-C & Sprite Kit太空历险记 : 5. 标准化装备——协议
- 字典类型
- 【codeforces】Pasha and Stick
- Ubuntu下adb 调试找不到device
- 写一个控制台运行的计算器
- Linux 的 NUMA 技术
- 查找最大元素 hd 2025