SurfaceView transparent through to its parent?

7581 views
Skip to first unread message

Blake B.

unread,
Feb 11, 2009, 9:46:27 PM2/11/09
to Android Developers
I have a SurfaceView that is covering a portion of its parent, a
RelativeLayout. I have a background image covering the full
RelativeLayout area, and this is my Activity's main layout.

I would like to have the SurfaceView be transparent so that I can see
through to the background image on its parent RelativeLayout. I have
tried the approach shown in the API Demos example
TranslucentGLSurfaceViewActivity, but this succeeds in making the
transparency go all the way through my Activity to my desktop!

I'm using the "style/Theme.Translucent" theme on my activity, and
setting this on my SurfaceView:
mySurfaceView.getHolder().setFormat(PixelFormat.RGBA_8888);

The transparency to the desktop it kinda cool, but not what I'm trying
to do! Is it possible to make a SurfaceView transparent only through
to its parent?

Thanks,
Blake

Dianne Hackborn

unread,
Feb 11, 2009, 10:09:04 PM2/11/09
to android-d...@googlegroups.com
The surface view is actually BEHIND your window, and a hole punched in the window for you to see it.  You thus can put things on top of it in your window, but nothing in your window can appear behind it.
--
Dianne Hackborn
Android framework engineer
hac...@android.com

Note: please don't send private questions to me, as I don't have time to provide private support.  All such questions should be posted on public forums, where I and others can see and answer them.

nmelo

unread,
Jan 28, 2012, 7:23:50 PM1/28/12
to android-d...@googlegroups.com
There is a solution to this problem posted on SO: 


Only reproducing the answer here for future reference: 

SurfaceView sfvTrack = (SurfaceView)findViewById(R.id.sfvTrack);
sfvTrack
.setZOrderOnTop(true);    // necessary
sfhTrack
= sfvTrack.getHolder();
sfhTrack
.setFormat(PixelFormat.TRANSPARENT);
Reply all
Reply to author
Forward
0 new messages