android群英传笔记--第三章--自定义控件四音频条形图
2016-10-26 23:01
357 查看
实现思路: 在onDraw 方法的for 循环中以依次出这些矩形,美观期间,给画笔增加一个渐变效果。
在onSizeChanged 方法中拿到尺寸
@Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); mWidth = getWidth(); mRectHeight = getHeight(); mRectWidth = (int) (mWidth * 0.6 / mRectCount); mLinearGradient = new LinearGradient( 0, 0, mRectWidth, mRectHeight, Color.YELLOW, Color.BLUE, Shader.TileMode.CLAMP); mPaint.setShader(mLinearGradient); }
onDraw中不停的重绘,这一个个方形。
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); for (int i = 0; i < mRectCount; i++) { mRandom = Math.random(); float currentHeight = (float) (mRectHeight * mRandom); canvas.drawRect( (float) (mWidth * 0.4 / 2 + mRectWidth * i + offset), currentHeight, (float) (mWidth * 0.4 / 2 + mRectWidth * (i + 1)), mRectHeight, mPaint); } postInvalidateDelayed(300); }
相关文章推荐
- android群英传笔记--第三章--自定义控件四音频条形图
- android群英传笔记--第三章--自定义控件四音频条形图
- android群英传笔记--第三章--自定义控件四音频条形图
- android群英传笔记--第三章--自定义控件四音频条形图
- android群英传笔记--第三章--自定义控件四音频条形图
- android群英传笔记--第三章--自定义控件四音频条形图
- android群英传笔记--第三章--自定义控件四音频条形图
- android群英传笔记--第三章--自定义控件四音频条形图
- android群英传笔记--第三章--自定义控件二topView的简单封装
- android群英传笔记--第三章--自定义控件二topView的简单封装
- android群英传笔记--第三章--自定义控件二topView的简单封装
- android群英传笔记--第三章--自定义控件三简单形状View
- android群英传笔记--第三章--自定义控件三简单形状View
- android群英传笔记--第三章--自定义控件三简单形状View
- android群英传笔记--第三章--自定义控件二topView的简单封装
- android群英传笔记--第三章--自定义控件二topView的简单封装
- android群英传笔记--第三章--自定义控件三简单形状View
- android群英传笔记--第三章--自定义控件二topView的简单封装
- android群英传笔记--第三章--自定义控件一跑马灯光扫过字体
- android群英传笔记--第三章--自定义控件一跑马灯光扫过字体