问题描述
如何编写将UI元素(按钮等)布局到Android上的相机预览的代码?
How do I write code which layouts UI elements (Buttons, etc) over camera preview on Android ?
推荐答案
在允许Z轴分层的容器中,例如 RelativeLayout 或 FrameLayout / code>。将 SurfaceView 顶部出现的东西放在后面的XML中 - 父对象的后续子对象将绘制在父对象的早期子对象之上。
Put the SurfaceView in a container that allows for Z-axis layering, such as RelativeLayout or FrameLayout. Put the things to appear on top of the SurfaceView later in the XML -- later children of a parent will draw over top of earlier children in the parent.
,使用 SurfaceView 用于演示该技术的视频播放。对于相机预览, SurfaceView 应该具有相同的概念。
Here is a project using a SurfaceView for video playback that demonstrates the technique. The same concepts should hold for a SurfaceView for camera preview.
请注意,需要完成额外的工作通过Android将您的小部件与预览混合,因此您的预览帧速率可能会下降。
Bear in mind that extra work needs to be done by Android to blend your widgets with the preview, so your preview frame rate may drop.
这篇关于Android上的相机预览UI叠加层?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!