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
1
vote
0 answers

Returning to video after setContentView()

I use a SurfaceView for displaying a video in my app, and it is released when I change the content view to somewhere else. My question is quite easy (I guess): When I want to switch back to the view with the video, I have to provide a new…
1
vote
1 answer

Surfaceview - Fatal Exception: Main

I'm a beginner to android, I believe my code is all fine but when loading the application in the emulator the application crash's and needs to be force closed. I get the bellow logcat, Ive searched the error but to be honest I don't understand…
Baggerz
  • 387
  • 6
  • 11
  • 24
1
vote
1 answer

Options for SurfaceView animation

I'm building an app for Android 2.2 that will be a sort of "fake" camera. I'm playing video using a SurfaceView and exposing controls to a user to take photos and flip between front & rear facing "cameras". I'd like to add animations for both that…
raydowe
  • 1,285
  • 1
  • 16
  • 31
1
vote
1 answer

Android - can't make the mole pop up

I am making an Android game. The game is moles that appear on different places on the screen at random intervals for random durations. The problem is I don't know how to make the mole stay visible for a few seconds. I used wait(1000) on the the…
cfircoo
  • 417
  • 2
  • 8
  • 23
1
vote
0 answers

Android SurfaceView different than saved image

I am creating a custom camera, in which I have 2 more bugs to fix before its finished. I'm here seeking help with 1 of them. I am trying to create a square preview (SurfaceView) and save that square to file. The only way I've been able to accomplish…
Rabbott
  • 4,282
  • 1
  • 30
  • 53
1
vote
1 answer

Render Byte Array on SurfaceView of android

Hi I have a raw dump of image which i store as byte array i have to display this on surface view. I tried to convert this byte array into a mutable bitmap and render on the canvas of surface holder but i get this null pointer…
amIT
  • 664
  • 13
  • 27
1
vote
1 answer

When onResume is called background goes blank

I have Dialog on transparent activity and it's like a pause menu, so when dialog is shown and I press Home button everything works fine but when I reopen it Dialog shows, except the background is blank. Game is made with canvas and SurfaceView so I…
Blake Gibbs
  • 485
  • 1
  • 9
  • 25
1
vote
2 answers

How to stop the SurfaceView in Android?

Recently when writing a game I experienced a problem. In my game I used SurfaceView and I used the while(true) as the condition. After I press the home button, the program quits and I see the log. But I find the loop While(true) is still running.…
Winnie
  • 769
  • 5
  • 23
1
vote
1 answer

Custom main menu with rotating android

I would like to make an application with a custom main menu. However, I want to have a different menu, with a circle and items around it. The user can select each item rotating the device. Should I use a Surface View to draw them and make the…
Black Hawk
  • 51
  • 2
  • 5
1
vote
2 answers

Android, regarding surfaecview and view

i have red around that surfaceview work faster in rendering, but take more resources than a view. from my testing, i tried this code: @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawColor(Color.WHITE); …
Daniel Mendel
  • 506
  • 5
  • 17
1
vote
1 answer

android - widget surfaceview?

I'm programming a widget. When somebody clicks on the widget Button, the Flashlight is turning on. If you click again on the widget button, the Flashlight is turning off. I wrote a small app, there its works, because i have a surface view in my…
user1205415
  • 605
  • 1
  • 7
  • 22
1
vote
1 answer

Canvas seems to draw on 2 different views

I am pretty new to Android development and I am trying to make a game in which my character moves on tiles across the screen. Since each tile is a bitmap of its own I redraw it after the character has moved on it. Now for some reason every time I…
Sagie Levy
  • 357
  • 3
  • 12
1
vote
3 answers

Camera is null when the surfaceCreated method is executed for second time

I have a problem with the camera object when the surfaceCreated method of a SurfaceHolder.Callback is called for second time, I mean: I create an object camera in my onResume method from my activity, and this works fine showing the preview display,…
1
vote
1 answer

what happens when new intent is called from view?

Im trying to start a new intent from my gameView using this method: if(happy.getHP() <= 0){ //if my main-character dies thread.setRunning(false); Context context = getContext(); Intent intent = new…
Green_qaue
  • 3,561
  • 11
  • 47
  • 89
1
vote
1 answer

SurfaceView + Canvas, fade from one color to another

I have ArrayList colors = new ArrayList(); for(int i = 0; i = intList.size(); i++){ //some list of ints colors.add(new ColorDrawable(intList.get(i))); I want to fade from one color in the list to another, using a…
snotyak
  • 3,709
  • 6
  • 35
  • 52
1 2 3
99
100