Android:是否可以使两个SurfaceView彼此重叠? [英] Android: Is it possible to have two surfaceview on top of each other?

查看:269
本文介绍了Android:是否可以使两个SurfaceView彼此重叠?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的想法是拥有两个surfaceViews.一个SurfaceView将保存图像(例如ImageSurgaceView),第二个表面位于第一个表面上,该第一个表面包含注释(例如AnnotationSurfaceView),例如圆形,矩形等.现在,我必须映射这些表面视图,以使高度,宽度相同,而且两个表面视图都应在拖动时移动,即共享触摸事件.确切地说,当我向上移动图像时,注释也应该向上移动.

My idea is to have two surfaceViews. One surfaceView which will hold an image (say ImageSurgaceView) and second surface that lie on top of the first one which holds the annotations (say AnnotationSurfaceView) like circle, rectangle etc. Now I have to map these surface views such that the height, width are same and moreover, both the surface view should move on drag i.e share the touch events. To be precise, when I move the image up the annotations should also move up.

现在,我不确定在Android中是否可行.任何人都可以告诉或分享一些有关此的信息.我对此没有任何实现想法,因此我没有任何特定的代码.而且,我找不到类似的东西.

Now, I am not sure if this is possible in android. Can any one tell or share some info on this. I don't have any implementation idea to this and hence I don't have any specific code. Moreover, I couldn't find anything similar.

感谢您的帮助.

推荐答案

是的,这是可能的.您可以将两个 SurfaceView 都添加为 FrameLayout 的子级.您还需要在一个或两个 SufaceView 来指定它们的分层方式.

Yes, this is possible. You can add both SurfaceViews as children of a FrameLayout. You will also want to call setZOrderMediaOverlay on one or both of your SufaceViews in order to specify how they are layered.

此外,这可能是您要描述的图形密集型算法.考虑添加 AndroidManifest.xml application 属性 android:hardwareAccelerated ="true" .

Furthermore, this could be a graphic intensive algorithm you are describing. Consider adding the AndroidManifest.xml application attribute android:hardwareAccelerated="true".

最后,只需设置自定义的 OnTouchListener 即可处理拖动事件.使用 MotionEvent.getRawX() MotionEvent.getRawY()来获取接触点,并以此来操纵画布.

Finally, just set up a custom OnTouchListener to handle drag events. Use MotionEvent.getRawX() and MotionEvent.getRawY() to get the touch point, and use this to manipulate the canvases.

这篇关于Android:是否可以使两个SurfaceView彼此重叠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆