下面就贴上一个小程序代码,主要运用SurfaceView来实现在屏幕上画一个圆,你可以通过按方向键和触摸屏幕来改变圆的位置


代码:

Activity

SurfaceView


MySurfaceView首先继承SurfaceView,然后实现Runnable和Callback接口

重写了Runnable的run方法和Callback的surfaceCreated(SurfaceHolder holder),surfaceChanged(SurfaceHolder holder, int format, int width,int height),surfaceDestroyed(SurfaceHolder holder)方法,

还实现了onTouchEvent(MotionEvent event),onKeyDown(int keyCode, KeyEvent event)方法来,详细的在代码里已注释。






相关文章:

  • 2022-01-06
  • 2021-08-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-06
  • 2022-12-23
  • 2021-11-20
  • 2021-05-29
  • 2021-11-08
  • 2021-12-31
相关资源
相似解决方案