onetouchdrawing攻略( 二 )

<=width) {y = (100*Math.sin(x*2*Math.PI/180)+400).toInt()mPath?.lineTo(x.toFloat(),y.toFloat())}else{break}}}}/*** 余弦函数*/inner class CosThread :Thread(){override fun run() {x =1y=0mPaint = Paint()mPaint?.strokeWidth=12fmPaint?.color = Color.BLUEmPath = Path()while (mIsDrawing) {try {mCanvas = holder.lockCanvas()mCanvas?.drawColor(Color.WHITE)mCanvas?.drawPath(mPath, mPaint)} catch (e: Exception) {e.printStackTrace()} finally {if (mCanvas != null) {holder?.unlockCanvasAndPost(mCanvas)}}x+=1if (x<=width) {y = (100*Math.cos(x*2*Math.PI/180)+400).toInt()mPath?.lineTo(x.toFloat(), y.toFloat())}else{break}}}}}如上,完成一个被动绘制和开放两个主动绘制的方法 。
2、在xml中使用
3、 在activity控制
【onetouchdrawing攻略】class CustomSurfaceActivity : AppCompatActivity() {override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_custom_surface)}/*** 点击事件监听*/fun onClick(view: View){when(view.id){R.id.beginDraw -> customerSurfaceView.refreshSin()R.id.cosDraw -> customerSurfaceView.cos()}}}


特别声明:本站内容均来自网友提供或互联网,仅供参考,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。