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
13
votes
2 answers

Pinch zoom on SurfaceView

I'm trying to implement pinch zoom on a SurfaceView. I've done a lot of research regarding this and I found this class to implement pinch zoom. Here is how I modified it: public class ZoomLayout extends FrameLayout implements…
ClassA
  • 2,480
  • 1
  • 26
  • 57
13
votes
4 answers

Android: creating a Bitmap with SurfaceView content

I'm afraid to already have the unfortunate answer to this question but just in case... I'm using a SurfaceView to do some image processing with bitmaps (lights and colors modifications) and I would need to import the modified bitmap (i.e. the…
Nicolas P.
  • 581
  • 1
  • 4
  • 15
13
votes
3 answers

How to attach MediaPlayer with SurfaceView in android?

I'm building video player with android media player object. i'm able to hear the audio but the video does not appear on surfaceView. here is my code public class PlayerActivity extends Activity implements SurfaceHolder.Callback { String…
Sujith S Manjavana
  • 1,417
  • 6
  • 33
  • 60
13
votes
6 answers

Set Background color of Surface View

I want to set a background color to the surface view to my camera surface view. I am using this for implementing the same. But this example is not complete. Can anyone please help me with some other useful link. Thanks
Gaurav Arora
  • 8,282
  • 21
  • 88
  • 143
13
votes
2 answers

Taking a picture as fast as possible with Camera API on Android

Scenario: I need to take a picture as fast as possible and save it to SD Card. It would be fantastic if I could do it in around 0.2 seconds both taking the picture and saving it. What I did so far: As normal I've created a SurfaceView to handle the…
Alin
  • 14,809
  • 40
  • 129
  • 218
13
votes
2 answers

Android SurfaceView scrolling

I'm writing an android application that builds an offscreen bitmap that is (say) 640*480 pixels and displays that in a SurfaceView. Note that the size of the image is larger than the actual display on the handset. The way that the application works…
Lee
  • 3,996
  • 3
  • 33
  • 37
12
votes
1 answer

Zoom effect on Android SurfaceView

I am developing a Car Race Game. I am able to move, stop, accelerate. But i want that when i press screen then car(bitmap of car image) should look like, it had jumped on its place.I am using surfaceviewto draw view I do not want to use 3D openGL.…
Tofeeq Ahmad
  • 11,935
  • 4
  • 61
  • 87
12
votes
4 answers

Fighting with SurfaceView, Camera and OpenGL

We've been fighting with some problems relating to SurfaceViews for more than a week, and find no proper solution to them. We read the other questions in the forum regarding to similar problems (and even Mixare source code) but couldn't find an…
saricchiella
  • 121
  • 1
  • 3
12
votes
3 answers

Weird performance issue with Galaxy Tab

I am working on a 2d tutorial and was able to test my current tutorial part on a Samsung Galaxy Tab. The tutorial simply moves the default icon randomly over the screen. With a tap I create a new moving icon. Everything works fine (constantly 60fps)…
WarrenFaith
  • 57,492
  • 25
  • 134
  • 150
12
votes
2 answers

Android Camera - Preview zooms in when recording video

I have been trying to figure this out for a while, but for some reason, when I start recording a video with the camera, the preview zooms in. I have the following code from some examples: @Override public void surfaceChanged(SurfaceHolder holder,…
Pink Jazz
  • 784
  • 4
  • 13
  • 34
12
votes
3 answers

Camera2 with a SurfaceView

I'm trying to get the new Camera2 working with a simple SurfaceView and I'm having some problems with the live preview. On some devices the image is stretched out of proportions while looking fine on others. I've setup a SurfaceView that I…
slott
  • 3,266
  • 1
  • 35
  • 30
12
votes
3 answers

Android Camera - app passed NULL surface

Whenever I run the cam_thread I get the error "app passed NULL surface". This code supposedly works on the HTC Incredible 1. I've reconfigured it slightly to run on a droid x. However I still get this error. public class Android_Activity extends…
EDPittore
  • 135
  • 1
  • 1
  • 6
11
votes
6 answers

Move an object on on a Bézier curve path

I want to move my image on a Bézier curve path from top to bottom but I can't get how can I calculate x/y points and slope from this path. The path looks like the following image: I have start points, end points and two control points. Path path =…
Sunny
  • 14,522
  • 15
  • 84
  • 129
11
votes
2 answers

How to make SurfaceView with transparent background?

I have simple layout
Dmitry Nelepov
  • 7,246
  • 8
  • 53
  • 74
11
votes
1 answer

Android:Crash: Binary XML file line : Error inflating class (using SurfaceView)

I'm having android surfaceView and in that I'm trying to add buttons to this. In the surfaceView canvas I draw something. And I have a thread class to keep drawing. package com.androidsurfaceview; import android.app.Activity; import…
m4n07
  • 2,267
  • 12
  • 50
  • 65