Android可设置结果的Loading
来源:互联网 发布:淘宝描述不符有赔偿吗 编辑:程序博客网 时间:2024/05/18 15:23
可以设置加载结果Loading控件。
效果图:
源码
package com.example.zloadingdemo;import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.graphics.RectF;import android.util.AttributeSet;import android.view.View;/** * Created by Zqil on 2017/5/20. */public class ZLoadingView extends View { private RectF mRectF = null; private int line1_x = 0; private int line1_y = 0; private int line2_x = 0; private int line2_y = 0; //画笔宽度 private int strokeWidth = 6; private int mState = 0; public static final int STATE_LOADING = 0; public static final int STATE_SUCCESS = 1; public static final int STATE_FAILED = -1; private final String colorLoading = "#00BAAF"; private final String colorSuccess = "#00BAAF"; private final String colorFailure = "#FF8C28"; public ZLoadingView(Context context) { super(context); } public ZLoadingView(Context context, AttributeSet attrs) { super(context, attrs); } public ZLoadingView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } boolean increasing = true; int start = 0; int sweep = 0; @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); /** * initialize paint */ Paint paint = new Paint(); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(strokeWidth); paint.setAntiAlias(true); if (mState == STATE_LOADING) { paint.setColor(Color.parseColor(colorLoading)); } else if (mState == STATE_SUCCESS) { paint.setColor(Color.parseColor(colorSuccess)); } else if (mState == STATE_FAILED) { paint.setColor(Color.parseColor(colorFailure)); } //圆弧半径 int radius = getWidth() / 2 - strokeWidth; if (mRectF == null) { mRectF = new RectF(strokeWidth, strokeWidth, getWidth() - strokeWidth, getWidth() - strokeWidth); } /** * paint loading * */ if (mState == STATE_LOADING) { if (sweep >= 340 && increasing) { increasing = false; } else if (sweep <= 20 && !increasing) { increasing = true; } if (increasing) { sweep+=10 ; start+=5; if (start>360) { start=start-360; } } else { start+=10 ; sweep-=5; } canvas.drawArc(mRectF, start, sweep, false, paint); postInvalidate(); } /** * paint result * */ boolean postPaint = true; int line1_startX = 0; int line1_startY = 0; int line1_width = 0; int line2_width = 0; int line2_startX = 0; int line2_startY = 0; if (mState == STATE_SUCCESS) { line1_startX = getWidth() * 3 / 10; line1_startY = getWidth() / 2; line1_width = radius / 3; line2_width = radius * 3 / 5; line2_startX = line1_startX + line1_width; line2_startY = line1_startY + line1_width; } else if (mState == STATE_FAILED) { line1_startX = getWidth() * 3 / 10; line1_startY = line1_startX; line1_width = getWidth() - line1_startX * 2; line2_width = line1_width; line2_startX = line1_startX; line2_startY = line1_startY + line1_width; } else { postPaint = false; } if (postPaint) { canvas.drawArc(mRectF, 0, 360, false, paint); //paint line1 canvas.drawLine(line1_startX, line1_startY, line1_startX + line1_x, line1_startY + line1_y, paint); //paint line2 canvas.drawLine(line2_startX, line2_startY, line2_startX + line2_x, line2_startY - line2_y, paint); if(line1_x <= line1_width) { line1_x++; line1_y++; } else if (line2_x < line2_width) { line2_x++; line2_y++; } else { postPaint = false; } if (postPaint) { postInvalidate(); } } } public void setState(int state) { if (this.mState != state) { line1_x = 0; line1_y = 0; line2_x = 0; line2_y = 0;} this.mState = state; postInvalidate(); } public void showLoading() { setState(STATE_LOADING); } public void showSuccess() { setState(STATE_SUCCESS); } public void showFailure() { setState(STATE_FAILED); }}
示例源码下载
阅读全文
0 0
- Android可设置结果的Loading
- Android设置loading的属性
- 可滚动的结果集
- 可滚动的结果集
- 测试可滚动的结果
- Android 请求网络loading 结果显示error empty界面
- Android Market的 Loading效果
- Android各种loading的效果
- Android 炫酷的loading
- Android简单的可设置间隔评分条的实现
- Android设置Settings:预读取设置的选项和更新设置结果【2】
- Android设置Settings:预读取设置的选项和更新设置结果【2】
- Android设置Settings:预读取设置的选项和更新设置结果【2】
- setTimeout妙用,可作loading功能,智能化的提示
- android 类似银行卡可设置分隔符的 EditText
- Android控件设置可点击
- 26可滚动的结果集
- 高效且可伸缩的结果缓存
- android6.0 wifi和以太网优先级修改
- react-native 滚动视图点击事件无法响应的情况
- vim快速移动
- 向Revit中批量导入运维信息
- Android studio修改图标/android 修改图标
- Android可设置结果的Loading
- maven,编译,代码过长
- 判断AngularJS渲染页面完成
- Unity利用JsonFX解析Json格式文本
- 试图加载格式不正确的程序。 (异常来自 HRESULT:0x8007000B)
- getpagesize()函数
- bootstrap-table合并单元格组合表头
- 使用反射对Servlet请求进行转发
- PostMan使用教程二 在test suite中运行test case