Questions tagged [surfaceview]

SurfaceView is a widget on the Android platform which provides a dedicated drawing surface.

Android's SurfaceView class provides a dedicated drawing surface embedded inside of a View hierarchy. You can control the format of this surface and, if you like, its size; the SurfaceView takes care of placing the surface at the correct location on the screen.

A SurfaceView has two parts: the Surface, and the View. The Surface is a separate layer, independent of the View UI layer; by default it is positioned behind the View layer. The View works like any other View element, and is usually completely transparent, serving only to interact with other View elements during layout. In some situations it can be useful to draw on the View (e.g. for a static mask).

Because the Surface is an independent layer, it can be updated outside of the usual invalidate/refresh View cycle, on a dedicated thread.

Allocation of a display Surface is performed by the Window Manager. This requires an IPC round-trip, so the availability of and changes to Surfaces are reported through callbacks. This also makes it difficult to move a SurfaceView around smoothly, as the position of the View and position of the Surface may not update on the same frame.

Other View elements can be positioned to overlap the SurfaceView, including interactive elements like buttons. The Surface's Z-order can be altered to place it on top of the View layer. It isn't possible to sandwich the Surface between View elements; if you need that, consider TextureView instead.

The transparent region that makes the surface visible is based on the layout positions in the view hierarchy. If the post-layout transform properties are used to draw a sibling view on top of the SurfaceView, the view may not be properly composited with the surface.

For many applications, a custom view is a better choice.

Detailed information about SurfaceView can be found in the system-level graphics architecture document.

2733 questions
11
votes
2 answers

How to properly use setZOrderMediaOverlay on Android?

Like many others, I am trying to draw 3D objects (using GLSurfaceView) on camera preview (using SurfaceView), along with some buttons placed on top. I actually got a prototype working, but I could not get the onResume working correctly. After a…
alokoko
  • 1,405
  • 4
  • 21
  • 35
11
votes
2 answers

When does surfaceDestroyed() occur

I'm having trouble figuring out when surfaceDestroyed() occurs. I am trying to make my threads stop running in the surfaceDestroyed() method (of a SurfaceView) but it appears that my surface is never actually destroyed...can someone tell me when…
Hani Honey
  • 2,101
  • 11
  • 48
  • 76
11
votes
1 answer

Android View vs SurfaceView vs GLSurfaceView for 2D drawing app with Zoomable User Interface

I plan to write a 2D drawing app with a zoomable user interface. With the app the user should be able to transform (translate and scale) drawn paths (and of course the UI). I assume that there will be up to 500 paths at the same time. Now, I am…
11
votes
7 answers

Clear video frame from surfaceview on video complete

I have created a media player which plays video on the surface view. After completion of video the last frame of the video remains on the surface. I want to remove the video frame from the surface because after some delay another video starts. The…
ishan jain
  • 681
  • 3
  • 10
  • 27
11
votes
1 answer

How come that a camera preview in a textureview is much more fuzzy than in a surfaceview?

I have found out that when using a textureview instead of a surfaceview as a camera preview (both hooked up to the camera via a mediarecorder) then the preview is much more fuzzy. What I mean by fuzzy is that in a texture view you can see the…
10
votes
3 answers

Support for multiple active overlapping surface views in Android

I am currently working on an Android App that needs several overlapping SurfaceViews in one screen. To be precise, I have two active overlapping SurfaceViews, one connected to Camera and the other connected to MediaPlayer. It mostly works but is…
Out Of Office
  • 427
  • 5
  • 13
10
votes
2 answers

Camera2 Pass Images from ImageReader to MediaRecorder

I'm trying to create a Camera2 CameraCaptureSession that is capable of four outputs: On-screen preview (SurfaceView, up to 1080p) Photo capture (ImageReader, up to 8k photos) Video Capture (MediaRecorder/MediaCodec, up to 4k videos) Frame…
10
votes
4 answers

surfaceCreated() Never Called

I've seen similar problems to the one I'm having, but I still can't find a solution. I'm very new to Android development, so I'm having trouble tracking down my problem. Anyways, I'm trying to create a camera preview using a CameraSurfaceView class…
jvhashe
  • 1,071
  • 2
  • 12
  • 15
10
votes
2 answers

How to get a SurfaceHolder with a valid Surface (needed by EGL.eglCreateWindowSurface)?

I try to initialize GLES with EGL (because I want to draw from the main thread instead of using a Renderer and drawing from inside onDrawFrame). I get the error: "Make sure the SurfaceView or associated SurfaceHolder has a valid Surface". Obviously…
Thomas Mertes
  • 101
  • 1
  • 1
  • 3
10
votes
2 answers

The efficiency about android canvas drawing

I've been wondering if canvas has a limit boundary. I mean if I use functions such asdrawline(), drawbitmap(), drawcircle(), does android really draw something on the canvas and waste some CPU cycles?? because after all the drawing functions, the…
Steven Shih
  • 645
  • 1
  • 10
  • 22
10
votes
3 answers

BufferQueue has been abandoned: When playing video with TextureView

Every time I pause my activity (actually Fragment) to go to another app, upon returning with onResume I try to resume the video playing but it does not play: I get a blank screen. Upon investigation, I see the following in the…
learner
  • 11,490
  • 26
  • 97
  • 169
10
votes
4 answers

Android's EditText is hidden when the virtual keyboard is shown and a SurfaceView is involved

I have a simple user interface: an EditText should be located below a SurfaceView. I use a RelativeLayout to arrange these two views. Now, when I tap on the EditText to open the virtual keyboard the SurfaceView slides up but the EditText is hidden…
Jan
  • 633
  • 11
  • 22
10
votes
1 answer

SurfaceView vs TextureView for Camera?

I want to incorporate a camera feature in my app, that will allow layout transitions of the view itself, changing its size, its preview size, and handle orientation changes efficiently. Should I use TextureView or SurfaceView? Decisions decisions..
OferM
  • 902
  • 1
  • 8
  • 20
10
votes
3 answers

Android - Take picture without preview

I am trying to take a picture without preview, immediately when my application starts running and after that to save the picture in new folder - "pictures123", in the root folder. Could someone please tell me what's wrong in my…
Eyal
  • 105
  • 1
  • 1
  • 7
10
votes
2 answers

"The surface has been released" error

I am creating a media player for online videos, but when I try to run it, I get this error: "The surface has been released". Here is my code: public class VideoSample1 extends Activity implements Callback, OnPreparedListener,…
AndroidOptimist
  • 1,419
  • 3
  • 23
  • 38