android 百分比loading,牛逼的loading加载效果
牛逼的loading加载效果
介绍:
AnimatedCircleLoadingView一个不错的loading加载效果,自定义AnimatedCircleLoadingView设置startDeterminate()
方法启动loading页面动画setPercent()设置loading进度 ,重置resetLoading(),等几个重要方法实现。
本例子来自:
本例子主要由TopCircleBorderView ,FinishedOkView,FinishedFailureView等实现。
主要代码实现类:
Java代码 复制代码
package com.github.jlmd.animatedcircleloadingview;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import com.github.jlmd.animatedcircleloadingview.animator.ViewAnimator;
import ponent.InitialCenterCircleView;
import ponent.MainCircleView;
import ponent.PercentIndicatorView;
import ponent.RightCircleView;
import ponent.SideArcsView;
import ponent.TopCircleBorderView;
import ponent.finish.FinishedFailureView;
import ponent.finish.FinishedOkView;
/**
* @author jlmd
*/
public class AnimatedCircleLoadingView extends FrameLayout {
private static final String DEFAULT_HEX_MAIN_COLOR = "#FF9A00";
private static final String DEFAULT_HEX_SECONDARY_COLOR = "#BDBDBD";
private final Context context;
private InitialCenterCircleView initialCenterCircleView;
private MainCircleView mainCircleView;
private RightCircleView rightCircleView;
private SideArcsView sideArcsView;
private TopCircleBorderView topCircleBorderView;
private FinishedOkView finishedOkView;
private FinishedFailureView finishedFailureView;
private PercentIndicatorView percentIndicatorView;
private ViewAnimator viewAnimator;
private boolean startAnimationIndeterminate;
private boolean startAnimationDeterminate;
private boolean stopAnimationOk;
private boolean stopAnimationFailure;
private int mainColor;
private int secondaryColor;
public AnimatedCircleLoadingView(Context context) {
super(context);
this.context = context;
}
public AnimatedCircleLoadingView(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
initAttributes(attrs);
}
public AnimatedCircleLoadingView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.context = context;
initAttributes(attrs);
}
private void initAttributes(AttributeSet attrs) {
TypedArray attributes =
getContext().obtainStyledAttributes(attrs, R.styleable.AnimatedCircleLoadingView);
mainColor = attributes.getColor(R.styleable.AnimatedCircleLoadingView_mainColor,
Color.parseColor(DEFAULT_HEX_MAIN_COLOR));
secondaryColor = attributes.getColor(R.styleable.AnimatedCircleLoadingView_secondaryColor,
Color.parseColor(DEFAULT_HEX_SECONDARY_COLOR));
attributes.recycle();
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
init();
startAnimation();
}
private void startAnimation() {
if (getWidth() != 0 && getHeight() != 0) {
if (startAnimationIndeterminate) {
viewAnimator.startAnimator();
startAnimationIndeterminate = false;
}
if (startAnimationDeterminate) {
addView(percentIndicatorView);
viewAnimator.startAnimator();
startAnimationDeterminate = false;
}
if (stopAnimationOk) {
stopOk();
}
if (stopAnimationFailure) {
stopFailure();
}
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// Force view to be a square
super.onMeasure(widthMeasureSpec, widthMeasureSpec);
}
private void init() {
initComponents();
addComponentsViews();
initAnimatorHelper();
}
private void initComponents() {
int width = getWidth();
initialCenterCircleView =
new InitialCenterCircleView(context, width, mainColor, secondaryColor);
rightCircleView = new RightCircleView(context, width, mainColor, secondaryColor);
sideArcsView = new SideArcsView(context, width, mainColor, secondaryColor);
topCircleBorderView = new TopCircleBorderView(context, width, mainColor, secondaryColor);
mainCircleView = new MainCircleView(context, width, mainColor, secondaryColor);
finishedOkView = new FinishedOkView(context, width, mainColor, secondaryColor);
finishedFailureView = new FinishedFailureView(context, width, mainColor, secondaryColor);
percentIndicatorView = new PercentIndicatorView(context, width);
}
private void addComponentsViews() {
addView(initialCenterCircleView);
addView(rightCircleView);
addView(sideArcsView);
addView(topCircleBorderView);
addView(mainCircleView);
addView(finishedOkView);
addView(finishedFailureView);
}
private void initAnimatorHelper() {
viewAnimator = new ViewAnimator();
viewAnimator.setComponentViewAnimations(initialCenterCircleView, rightCircleView, sideArcsView,
topCircleBorderView, mainCircleView, finishedOkView, finishedFailureView,
percentIndicatorView);
}
public void startIndeterminate() {
startAnimationIndeterminate = true;
startAnimation();
}
public void startDeterminate() {
startAnimationDeterminate = true;
startAnimation();
}
public void setPercent(int percent) {
if (percentIndicatorView != null) {
percentIndicatorView.setPercent(percent);
if (percent == 100) {
viewAnimator.finishOk();
}
}
}
public void stopOk() {
if (viewAnimator == null) {
stopAnimationOk = true;
} else {
viewAnimator.finishOk();
}
}
public void stopFailure() {
if (viewAnimator == null) {
stopAnimationFailure = true;
} else {
viewAnimator.finishFailure();
}
}
public void resetLoading() {
viewAnimator.resetAnimator();
setPercent(0);
}
}
///代码调用
public class MainActivity extends Activity {
private AnimatedCircleLoadingView animatedCircleLoadingView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
animatedCircleLoadingView = (AnimatedCircleLoadingView) findViewById(R.id.circle_loading_view);
startLoading();
startPercentMockThread();
}
private void startLoading() {
animatedCircleLoadingView.startDeterminate();
}
private void startPercentMockThread() {
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
Thread.sleep(1500);
for (int i = 0; i <= 100; i++) {
Thread.sleep(65);
changePercent(i);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
new Thread(runnable).start();
}
private void changePercent(final int percent) {
runOnUiThread(new Runnable() {
@Override
public void run() {
animatedCircleLoadingView.setPercent(percent);
}
});
}
public void resetLoading() {
runOnUiThread(new Runnable() {
@Override
public void run() {
animatedCircleLoadingView.resetLoading();
}
});
}
}
android 百分比loading,牛逼的loading加载效果相关推荐
- 这是我见过最牛逼的滑动加载前端框架
文章目录 前言 一.mescroll简介 二.快速开始 三.一分钟入门mescroll图片懒加载 四.mescroll在vue中的使用 五.小结 前言 在手机端实现下拉刷新和下拉加载是最常见不过的需求 ...
- Android 仿微信小程序开屏页加载loading
Android 仿微信小程序开屏页加载loading 废话不多说,先上效果图~ 首先就是底层有一个灰色的圆,然后按照圆形的轨迹进行绘制. 啊~说那么多也没用,还是直接上代码吧,哈哈哈哈 绘制底部圆形及 ...
- android 自定义加载动画效果,Android自定义View实现loading动画加载效果
项目开发中对Loading的处理是比较常见的,安卓系统提供的不太美观,引入第三发又太麻烦,这时候自己定义View来实现这个效果,并且进行封装抽取给项目提供统一的loading样式是最好的解决方式了. ...
- axios vue 加载效果动画_vue+axios+element ui 实现全局loading加载示例
实现全局loading加载 分析需求,我们只需要在请求发起的时候开始loading,响应结束的时候关闭loading,就这么简单 对不对? import axios from 'axios'; imp ...
- 使用HTML+CSS实现网页loading加载效果,支持定时或加载完成后隐藏
网页使用loading可以给用户带来更好的体验,避免网页渲染中长时间出现网页整体空白从而影响访客的体验,loading在部分大型APP也有在应用. 下面使用HTML+CSS+JS实现完整的Loadin ...
- jquery实现文件上传及loading加载效果
jQuery实现文件上传步骤 1.定义UI结构 2.验证是否选择了文件 3.向formdata中追加文件 4.使用jQuery的Ajax发起上传文件的请求 核心代码 1.ajaxStart(callb ...
- vue项目中,设置页面局部loading加载效果(element)
直接引用element的loading,默认的是全屏loading,实际中有很多地方不需要全屏loading,只需要某部分loading,如上图 话不多说,直接上代码 封装好的loading.js i ...
- element使用自定义的loading加载效果
在使用loading加载的过程中,elementui提供了两种样式,但是针对不同的项目,也是有着不同的需求,需要不同的或者特制的loading加载效果. 解决思路如下: 结合elementui本身的标 ...
- CSS Loading 加载效果
平滑加载 /* 平滑加载 */ .progress-1 {width: 120px;height: 20px;background: linear-gradient(#000 0 0) 0/0% no ...
最新文章
- 机器学习模型部署_9月版部署机器学习模型
- android 浏览器 pc一样大小,手机端不同浏览器[主流的,包括Android自带]对cookie的不同限制,如个数和大小,如何查看?...
- python切面异常处理_Spring项目中优雅的异常处理
- 云上自动化 vs 云上编排
- Bella Protocol已按计划调整流动性挖矿奖励方案
- Kali Linux镜像安装(1)
- 联想微型计算机c255r拆机,联想R9000P开箱拆机,送给你的618选购参考
- JAVA复习 (期末重点考点总结)
- html模拟鼠标点击图标,易语言模拟鼠标点击实现方法
- elixir 规格_六家使用Elixir的著名公司-以及为什么做出改变
- 计算机导论——计算机软件03
- 云出阿里见月明(上)
- 批规范化 Batch Normalization
- ueditor word粘贴上传
- MATLAB矩阵与阵列
- 地区数据erea.js
- 【Unity3D—C#】按下任意按键,返回按键的名称 以及 KeyCode键码详解
- 纯原创最全Redis面试题整理
- 操作系统学习笔记——北京大学陈向群老师课后及习题答案(4)
- 小型计算机系统接口是什么,小型计算机系统接口是什么