It's probably not the best way, but right now you simply can not have
multiple overlapping surface views in a window, so the only way to achieve
this is to render the overlay in the main window.  Fyi, using a separate
thread and postInvalidate() is extra work that is not needed, just call
invalidate() from the main thread.  And you'll want to make sure that at
least the part of your view hierarchy involved with drawing the overlay is
as simply as possible (not deep and not a lot of views to iterate over) to
reduce the overhead as much as possible.

On Tue, Jul 28, 2009 at 2:18 AM, Chris <chrismc...@hotmail.com> wrote:

>
> Thanks for the indepth reply!
>
> Maybe you as Android Framework Developer can give a recommendation on
> how I best implement the following: I have camera preview and want to
> overlay my own item over this that change very quickly (about every
> 200ms).
>
> The camera preview uses a SurfaceView as in the samples. As first
> approach I used a normal View as the overlay part and called
> postInvalidate from another thread very often to redraw the View. This
> caused heavy CPU load (90%) of my application. Now, I managed to use
> two SurfaceViews and making one transparent. This also works and the
> CPU load is about 30% now.
>
> However: is this the best way to implement such functionality?
>
> Thanks!
> Chris
>
>
> On Jul 27, 8:07 pm, Dianne Hackborn <hack...@android.com> wrote:
> > Sorry, you can't do this -- because surface views are very special and
> not
> > really views (the surface is a separate window Z-ordered with your own),
> > their Z-ordering does not match your views.  A surface view is a big,
> heavy
> > object; you are not intended to treat SurfaceView like a regular view in
> > this way.
> >
> > As far as transparency, the surface is transparent if you make its pixel
> > format transparent.  It's your surface, you can do with it what you want.
> > The default is to be the same pixel format as the screen, since that is
> the
> > most efficient and it is very rare for someone to want a transparent
> surface
> > view.
> >
> > The way you really are intended to do this is to own the surface, and
> draw
> > all your compositing in there.  So you would just have one surface view
> that
> > you are updating in the places where either the background or overlay is
> > changing.  To be honest, I think you are going to get better performance
> if
> > you do it this way anyway, especially if you use OpenGL.
> >
> > For simple overlays, one thing that is reasonable to do is to stick the
> > SurfaceView in a frame layout, Z-ordering it below other -regular- views
> > that contain the overlay.  There is an example in ApiDemos of this.
> >
> >
> >
> > On Mon, Jul 27, 2009 at 7:34 AM, Chris <chrismc...@hotmail.com> wrote:
> >
> > > Hi,
> >
> > > I have two SurfaceViews in one FrameLayout. So they are stacked upon
> > > another. What I want to achieve is to use the lower SurfaceView as
> > > kind of background that is changing heavily, and the upper SurfaceView
> > > as annotation overlay. So the upper SurfaceView has a (small) number
> > > of quickly changing elements that I will draw.
> >
> > > Somehow, I can always only see one of the SurfaceViews, depending on
> > > which one is top. I thought that SurfaceViews are always transparent,
> > > but it seems I am missing something here.
> >
> > > Any thoughts on why I can't overlay two SurfaceViews?
> >
> > > Thanks,
> > > Chris
> >
> > --
> > Dianne Hackborn
> > Android framework engineer
> > hack...@android.com
> >
> > Note: please don't send private questions to me, as I don't have time to
> > provide private support, and so won't reply to such e-mails.  All such
> > questions should be posted on public forums, where I and others can see
> and
> > answer them.
> >
>


-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

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

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to