开发者

Adding ImageViews to SurfaceView

I am developing game in android. In my game i have SurfaceView(i.e., GameView) which is set on setC开发者_如何学PythonontentView(new GameView(this));. During the runtime i have to add no of imageviews to the surface view. Each ImageView should listen for TouchEvent. and now How to add ImageViews to surfaceview?


I might be wrong, but after using SurfaceView myself, I think that this type of view draws graphics via the onDraw() method that has to be implemented. Hopefully you understand that the onDraw() basically draws things for the Canvas class and includes stuff like drawBitmap (which you can draw certain images from your drawables resources). The way I add images is just...

yourCanvas.drawBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.image), x, y, yourPaint);

As for listening for a TouchEvent, I'm not exactly sure what you would do because you obviously can't listen for TouchEvents on drawn Bitmaps. I may suggest a more tedious alternative which is to track the coordinates of the user's finger through a onTouchEvent(MotionEvent event).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜