android 等待圈_Android中自定义View实现圆环等待及相关的音量调节效果

圆环交替、等待效果

效果就这样,分析了一下,大概有这几个属性,两个颜色,一个速度,一个圆环的宽度。

自定View的几个步骤:

1、自定义View的属性

2、在View的构造方法中获得我们自定义的属性

3、重写onMesure

4、重写onDraw

1、自定义属性:

2、在View的构造方法中获得我们自定义的属性

/**

* 第一圈的颜色

*/

private int mFirstColor;

/**

* 第二圈的颜色

*/

private int mSecondColor;

/**

* 圈的宽度

*/

private int mCircleWidth;

/**

* 画笔

*/

private Paint mPaint;

/**

* 当前进度

*/

private int mProgress;

/**

* 速度

*/

private int mSpeed;

/**

* 是否应该开始下一个

*/

private boolean isNext = false;

public CustomProgressBar(Context context, AttributeSet attrs)

{

this(context, attrs, 0);

}

public CustomProgressBar(Context context)

{

this(context, null);

}

/**

* 必要的初始化,获得一些自定义的值

*

* @param context

* @param attrs

* @param defStyle

*/

public CustomProgressBar(Context context, AttributeSet attrs, int defStyle)

{

super(context, attrs, defStyle);

TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CustomProgressBar, defStyle, 0);

int n = a.getIndexCount();

for (int i = 0; i < n; i++)

{

int attr = a.getIndex(i);

switch (attr)

{

case R.styleable.CustomProgressBar_firstColor:

mFirstColor = a.getColor(attr, Color.GREEN);

break;

case R.styleable.CustomProgressBar_secondColor:

mSecondColor = a.getColor(attr, Color.RED);

break;

case R.styleable.CustomProgressBar_circleWidth:

mCircleWidth = a.getDimensionPixelSize(attr, (int) TypedValue.applyDimension(

TypedValue.COMPLEX_UNIT_PX, 20, getResources().getDisplayMetrics())

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值