自定义View
package gg.bw.com.wangshu20190404; import android.content.Context; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Path; import android.util.AttributeSet; import android.view.View; public class WaterView2 extends View { Paint paint = new Paint(); Path path = new Path(); float mt; public WaterView2(Context context) { super(context); paint.setAntiAlias(true); } public WaterView2(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); path.reset(); path.moveTo(getLeft(),getBottom()); float v = (float) (Math.PI *2/ getRight()); mt-=0.1; for (int i = 0; i <=getRight() ; i+=20) { path.lineTo(i, (float) (10 * Math.cos(v * i +mt)+ 10)); } path.lineTo(getRight(),getBottom()); canvas.drawPath(path,paint); postInvalidateDelayed(20); } }
文章来源: https://blog.csdn.net/weixin_44405056/article/details/89064776