android 百分比loading,牛逼的loading加载效果

牛逼的loading加载效果

介绍:

AnimatedCircleLoadingView一个不错的loading加载效果,自定义AnimatedCircleLoadingView设置startDeterminate()

方法启动loading页面动画setPercent()设置loading进度 ,重置resetLoading(),等几个重要方法实现。

本例子来自:

本例子主要由TopCircleBorderView ,FinishedOkView,FinishedFailureView等实现。

55550.html

主要代码实现类:

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();

}

});

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值