效果图
最近想着对UI的提升,然后顺便写了个进度条玩玩,暂时没写完,不过已经把核心部分的写好了,剩下的都简单,水友们可以自由发挥,废话不多说,先上代码。
package com.yyx.iwidget.view;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PaintFlagsDrawFilter;
import android.graphics.Path;
import android.graphics.RectF;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
public class IWaveView extends View {
private Paint forePaint;//前景色paint
private Paint bgdPaint;//背景色paint
private final int waveHeight = 10;//波浪高度
private final float waveWidth = (float) 1.0;//波浪宽度 越大越窄
private float offsetX = 0;//横向偏移量
private float offsetY = 0;//纵向偏移量
private int animTime = 35;//动画时间 单位 毫秒
private float startX = 0;//起始点X坐标
private float endX = 0;//结束点X坐标
private float endY = 0;//结束点Y坐标
private Path forePath;//前景绘制路径
private Path bgdPath;//背景绘制路径
private Handler handler;
private Runnable runnable;
public IWaveView(Context context) {
super(context);
init(context, null);
}
public IWaveView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public IWaveView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
//初始化
private void init(Context context, @Nullable AttributeSet attrs) {
forePaint = new Paint();
forePaint.setColor(Color.RED);
forePaint.setAntiAlias(true);
bgdPaint = new Paint();
bgdPaint.setColor(Color.parseColor("#33ff0000"));
bgdPaint.setAntiAlias(true);
forePath = new Path();
bgdPath = new Path();
offsetY = getHeight();
startAnim();
}
@Override
protected void onDraw(final Canvas canvas) {
super.onDraw(canvas);
int width = getWidth(