Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Camera preview UI overlay on Android?

How do I write code which layouts UI elements (Buttons, etc) over camera preview on Android ?

like image 493
Eli Ben-Ami Avatar asked Dec 27 '09 15:12

Eli Ben-Ami


1 Answers

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.

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.

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.

like image 152
CommonsWare Avatar answered Sep 30 '22 03:09

CommonsWare