所以我正在制作一个需要绘制花环,灯泡和其他装饰的应用程序。我有一个可以在Action_Move上进行图像查看的代码,但该应用程序崩溃了。参见下面的代码
fun drawLights(){
val listener = View.OnTouchListener(function = { view, motionEvent ->
val x = motionEvent.getX()
val y = motionEvent.getY()
when (motionEvent.action){
MotionEvent.ACTION_DOWN -> {
Toast.makeText(this,"Action Down",Toast.LENGTH_SHORT).show()
}
MotionEvent.ACTION_MOVE -> {
Toast.makeText(this, "Moving", Toast.LENGTH_SHORT).show()
////Imageview Creation Here using late init var
}
MotionEvent.ACTION_UP -> {
Toast.makeText(this,"Done" ,Toast.LENGTH_SHORT).show()
}
}
true
})
edit_Canvas.setOnTouchListener(listener)
}
这里的任何人都知道与此相关的任何博客或已解决此问题吗?谢谢!
您需要在Android Canvas上查找有关绘画的主题。那里有很多示例代码
这是来自官方文档的画布https://developer.android.com/training/custom-views/custom-drawing上的绘图>