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
10
votes
1 answer

Android: Is it possible to have two surfaceview on top of each other?

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…
Shobhit
  • 407
  • 5
  • 15
10
votes
1 answer

Fix Android Camera app aspect ratio and rotation

How it looks: http://i41.tinypic.com/30278m1.png It looks like in the pic ,I want it to have a correct aspect ratio with correct rotaion Take a look the code please , how can I fix it ? This is my code: public class MainActivity extends Activity…
A.Jouni
  • 377
  • 2
  • 4
  • 14
10
votes
5 answers

Android draw using SurfaceView and Thread

I am trying to draw a ball to my screen using 3 classes. I have read a little about this and I found a code snippet that works using the 3 classes on one page, Playing with graphics in Android I altered the code so that I have a ball that is moving…
Morten Høgseth
  • 338
  • 2
  • 4
  • 17
10
votes
4 answers

Take Picture without preview Android

I would like to take a picture without any preview. I used this code but I'm getting an error: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Camera.Parameters…
113408
  • 3,364
  • 6
  • 27
  • 54
10
votes
3 answers

Android: onPreviewFrame never called without SurfaceView

On some devices, onPreviewFrame is not called if no SurfaceView was set to display the camera preview. However, I handle the camera in a service, so I can't set a SurfaceView but I don't want to have visible preview anyway. How can this be done? Can…
DominicM
  • 2,186
  • 5
  • 24
  • 42
9
votes
1 answer

SurfaceView and ANativeWindow

I have a question regarding creation of a SurfaceView and subsequently getting a ANativeWindow from it. Is it proper to do mSurfaceView = new SurfaceView(this); in: onCreate() onStart() Reason for asking: as I understand it the SurfaceView will…
gadget
  • 2,082
  • 2
  • 14
  • 11
9
votes
1 answer

Using surfaceView to capture a video

I have an Application in that I want to capture video using Surfaceview and stored it in my own created folder it is possible? It stored video only default folder. Thanks in andvace.....
pratik
  • 983
  • 3
  • 13
  • 25
9
votes
6 answers

surface view does not show camera after i gave permission

public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_camera, container, false); cameraId = Camera.CameraInfo.CAMERA_FACING_BACK; …
Velayutham M
  • 1,119
  • 14
  • 18
9
votes
4 answers

Android SurfaceHolder.unlockCanvasAndPost() does not cause redraw

I'm implementing a fairly standard app with the Android sdk that involves drawing using the SurfaceView, SurfaceHolder, Callback setup. In my main thread (UI thread) I have no drawing or handling of the SurfaceHolder (or the canvas you retrieve with…
cblades
  • 416
  • 3
  • 11
9
votes
0 answers

how to create and save a screenshot from a surfaceview?

I have an app that I want to be able to capture a screenshot Here is my code : public class Screenshot { private final View view; /** Create snapshots based on the view and its children. */ public Screenshot(View root) { …
natuan241
  • 751
  • 3
  • 7
  • 11
9
votes
5 answers

SurfaceView shows black screen - Android

Basically I want to use SurfaceView for animation. Therefore the class implements Runnable. To experiment, I want to draw a circle. However, it shows only a black screen. I have been trying for days. Really appreciate if someone can…
Wallyfull
  • 181
  • 1
  • 2
  • 16
9
votes
4 answers

surfaceview + glsurfaceview + framelayout

I'm new at java and OpenGL. I'm trying to get a camera preview screen with the ability to display 3d objects simultaneously. Having gone through the samples at the api demos, I thought combining the code for the the examples at the api demo would…
pohtzeyun
  • 113
  • 1
  • 1
  • 6
9
votes
3 answers

Android canvas fill background color (Canvas application)

By having the following codes, I have some questions. public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView( new View(this) { …
Sam
  • 4,521
  • 13
  • 46
  • 81
9
votes
1 answer

MediaCodec createInputSurface

I want to use MediaCodec to encode a Surface into H.264. With API 18, there is a way to encode content from a surface by calling createInputSurface() and then drawing on that surface. I get IllegalStateException on createInputSurface(). Here's…
Broatian
  • 860
  • 9
  • 10
9
votes
2 answers

How to take a screenshot of Android's Surface View?

I want to programatically take screen shot of my game, just as you'd get in Eclipse DDMS. Screenshot taken through the solution proposed here: How to programmatically take a screenshot in Android? and in most other SO questions only have View…
Tariq Mahmood
  • 91
  • 1
  • 1
  • 2