SurfaceView won't draw while under image view - android

I have a function that will keep on drawing on the surfaceView to simulate the animation of a character on the surfaceView. But after adding a imageView on top of the SurfaceView, the SurfaceView stop drawing.

setZOrderOnTop(true) you have added in the surfaceview init.
because surfaceview should be always on top to draw anything,
Although after that you can't put image on top of that, for that you can use other question ref
add image to surface view in android
for that. let me know if that helps

Related

Create cameraview (mask) on surfaceview in android

I want to create a mask on camera surface view. see image below. mask is resizable. image will be clicked only by unblurred area. can anybody give idea how to create suh mask? thanks in advance.
You can't draw on the Surface of the SurfaceView that is receiving the camera preview.
You have two basic options: draw on the View part of the SurfaceView, treating it as a custom view, or create a second SurfaceView and layer it on top of the camera surface.
For the latter, you would use setZOrderMediaOverlay() to position the Surface above the camera Surface layer but below the View UI layer. You can use Canvas or GLES to draw on it. You can find an example of an activity with three SurfaceViews in Grafika's "multi-surface test".
You can draw on a surfaceview with camera preview. You need to set the
setWillNotDraw(false);
in surfaceCreated override.
See: Extended SurfaceView's onDraw() method never called
So from there on, do all your drawing in onDraw as normal.

Layering Views on a SurfaceView

I am trying to build a simple game. I have a SurfaceView, on which I draw the background for the game:
Canvas canvas = surfaceHolder.lockCanvas();
//draw on canvas....
surfaceHolder.unlockCanvasAndPost(canvas);
I have a View that I want to 'layer' on top of the SurfaceView, but I still want to be able to see the background underneath it. How do I draw the view on top of the SurfaceView. The View has its own onDraw method, with an associated canvas, so I'm assuming that I need to place the View on top of the SurfaceView where I drew the background?
There may be a more efficient way to to do this, but when it comes to stacking views on top of one another, you could put the SurfaceView inside a FrameLayout, and then put the view you want on top after the SurfaceView in the XML, but still inside the FrameLayout (meaning it's drawn later, and thus on top). This will accomplish the stacking you desire.
If you wish to position the view that will go on top of the SurfaceView anywhere else than exactly matching it, or the top left, then you could use a RelativeLayout where you layout the SurfaceView with alightParentLeft, alightParentTop, alignParentBottom, and alightParentRight all set to true. Then again having the view you want drawn on top coming after the SurfaceView in xml will draw it on top, and you can position it wherever you want.
Now as for you wanting to the view on top of the SurfaceView to be see through, you can do that by setting it's alpha value. if you are aiming for 3.0+ you can just use a view's .setAlpha method, but if you are aiming for lower, you could set a zero millisecond AlphaAnimation to set the alpha of the view (There may be a better way to do this, but this is the only way I to set alpha on views pre honeycomb).
Hope this helps! Best of luck!

How to draw scrollbar at particular position in a surfaceview in android

I am taking a surfaceview in xml file and drawing text,rectangle on the surfaceview by overriding ondraw() method and I want to make some part as a scrollable at surfaceview.
for reference--
https://www.youtube.com/watch?v=ycYp356qrno
in this app one page where all task are display and progress status is scrollable
pls help...

Camera just a portion of a SurfaceView

Is it possible to draw the camera in just a portion of the SurfaceView?
or draw different things on the same SurfaceView?
What do you want to achieve by that? You cannot send the camera preview to a portion of a SurfaceView, but you can adjust the size of this View, and put other views around it or even on top of it. The latter is an alternative to drawing different things on the same SurfaceView.

How to add the camera as canvas background

I have a simple app with graphics moving about on a canvas, implemented in a surfaceview, i.e. not using an xml layout.
Is there an easy way to use the camera preview as the background?
You could use a FrameLayout and put first your surfaceView as a child and then some other view with no/transparent background.
A FrameLayout draws its children in the order of adding.

Categories

Resources