自定义MaterialProgressBarSupport
2015-12-29 18:29
417 查看
package com.ybzf.mobile.pharmacist.views; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Color; import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup; import com.ybzf.mobile.pharmacist.R; /** * Created on 15/08/01 */ public class MaterialProgressBarSupport extends ViewGroup { // Default background for the progress spinner private static final int CIRCLE_BG_LIGHT = 0xFFFAFAFA; private static final int CIRCLE_LIGHT = Color.BLACK; // Default offset in dips from the top of the view to where the progress spinner should stop private static final int DEFAULT_CIRCLE_TARGET = 64; private static final int CIRCLE_DIAMETER = 40; private static final int CIRCLE_DIAMETER_LARGE = 56; private static final int MAX_ALPHA = 255; private MaterialProgressDrawableSupport mProgress; private CircleImageViewSupport mCircleView; public MaterialProgressBarSupport(Context context) { this(context, null); } public MaterialProgressBarSupport(Context context, AttributeSet attrs) { super(context, attrs); createProgressView(attrs); } private void createProgressView(AttributeSet attrs) { int progressSize = CIRCLE_DIAMETER; int bgColor = CIRCLE_BG_LIGHT; int progressColor = CIRCLE_LIGHT; final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.MaterialProgressBarSupport); if (a.hasValue(R.styleable.MaterialProgressBarSupport_progressSmallSize)) { boolean isSmallSize = a.getBoolean(R.styleable.MaterialProgressBarSupport_progressSmallSize, true); progressSize = isSmallSize ? CIRCLE_DIAMETER : CIRCLE_DIAMETER_LARGE; } if (a.hasValue(R.styleable.MaterialProgressBarSupport_progressBackgroundColor)) { bgColor = a.getColor(R.styleable.MaterialProgressBarSupport_progressBackgroundColor, CIRCLE_BG_LIGHT); } if (a.hasValue(R.styleable.MaterialProgressBarSupport_progressColor)) { progressColor = a.getColor(R.styleable.MaterialProgressBarSupport_progressColor, CIRCLE_LIGHT); } //TypedArray使用完回收 a.recycle(); mCircleView = new CircleImageViewSupport(getContext(), bgColor, progressSize / 2); mProgress = new MaterialProgressDrawableSupport(getContext(), this); mProgress.setColorSchemeColors(progressColor); mCircleView.setImageDrawable(mProgress); addView(mCircleView); } @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { mCircleView.layout(l, t, r, b); } public void startProgress(){ mCircleView.setVisibility(View.VISIBLE); mProgress.setAlpha(MAX_ALPHA); mProgress.start(); } public void stopProgress(){ mCircleView.setVisibility(View.GONE); mProgress.stop(); } }
相关文章推荐
- LINUX 文件I/O
- 从通知栏进入应用中的某一页面,回退事件的处理
- Liquidfun的编译与运行
- 图片上传webuploader
- [Vue warn]: Cannot find element: #main
- hessian 使用token安全机制
- 【斜率DP】BZOJ 1911:特别行动队
- POJ 1274 The Perfect Stall(二分匹配-hungary)
- Android 之 注解
- 在Hibernate工程中如何让数据库从MYSQL换成ORACLE
- 静态数据成员与静态成员函数
- ZOJ 3329 One Person Game (概率DP)
- Java SE | SSM 日期类型的转换 由String 转换为Date
- IOS 程序执行
- java中的反射
- jQuery:常用方法一览
- 001: Hello World
- Android自定义组合控件
- Revit二次开发之“族”操作
- iOS解决Cell的分割线宽度不满屏的方法