Android SurfaceView drawing

南楼画角 提交于 2019-12-10 10:46:03

问题


I am new in android. I reviewed two examples Custom View with User Interaction and Android SurfaceView. I want that in second example draw cicle similarly with first example. How I can do this? Second question is: when the run() method has to stop?


回答1:


I found solution. For correctly work of SurfaceView I had to set background of canvas. When I done it everything is working fine.




回答2:


Create A bitmap then draw on its canvas and then add this bitmap to an imageview.

Create A bitmap:

    Bitmap bmp = Bitmap.createBitmap(width, height, config);

Draw on the bitmap canvas

    Canvas cv = new Canvas(bmp);
    cv.drawCircle(cx, cy, radius, paint)

setting to imageview

    img.setBackgroundDrawable(new BitmapDrawable(bmp));

Hope his help you.



来源:https://stackoverflow.com/questions/14139177/android-surfaceview-drawing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!