Android自定义谷歌风格自定义谷歌风格ProgressBar
本文实例为大家分享了谷歌风格ProgressBar的具体代码,供大家参考,具体内容如下
具体代码
package zms.demo.colorprogress;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
import android.widget.ProgressBar;
public class GoogleProgressBar extends ProgressBar {
private static final int INTERPOLATOR_ACCELERATE = 0;
private static final int INTERPOLATOR_LINEAR = 1;
private static final int INTERPOLATOR_ACCELERATEDECELERATE = 2;
private static final int INTERPOLATOR_DECELERATE = 3;
public GoogleProgressBar(Context context) {
this(context, null);
}
public GoogleProgressBar(Context context, AttributeSet attrs) {
this(context, attrs, R.attr.googleProgressStyle);
}
public GoogleProgressBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
if (isInEditMode()) {
setIndeterminateDrawable(new GoogleProgressDrawable.Builder(
context, true).build());
return;
}
Resources res = context.getResources();
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.GoogleStyleProgressBar, defStyle, 0);
final int color = a.getColor(R.styleable.GoogleStyleProgressBar_color,
res.getColor(R.color.default_color));
final int sectionsCount = a.getInteger(
R.styleable.GoogleStyleProgressBar_sections_count,
res.getInteger(R.integer.default_sections_count));
final int separatorLength = a
.getDimensionPixelSize(
R.styleable.GoogleStyleProgressBar_stroke_separator_length,
res.getDimensionPixelSize(R.dimen.default_stroke_separator_length));
final float strokeWidth = a.getDimension(
R.styleable.GoogleStyleProgressBar_stroke_width,
res.getDimension(R.dimen.default_stroke_width));
final float speed = a.getFloat(
评论0
最新资源