Hi all, I've followed this thread with interest because I had intended to do something very similar; that is, have multiple pages that the user can swipe between (using a ViewFlipper) where some screens may be composed of a mixture of SurfaceViews and normal Views. To be clear, I don't wish to have SurfaceViews at or greater than screen size; rather, just some of my smaller screen components are made using SurfaceViews. Now, after working with SurfaceViews quite a bit, I'm quite happy in my understanding of why a SurfaceView is special, and how it is effectively removed from the normal View hierarchy. (In simplistic terms, I think of the SurfaceView as a means of handing control of a specified screen video memory area directly to the application, with the benefit of separately-threaded update performance, but obvious cost of interaction with normal View hierarchy).
Having read this discussion, what I'm not quite clear about in my head at the moment is exactly which combinations of ViewGroup container and SurfaceView are either just 'bad' (and why) or simply won't work. For example, for my application where the user can swipe between multiple pages of a dashboard in order to view various dashboard components (where some are made using SurfaceViews) I considered using a HorizontalScrollView. However, doing some Googling I did come across Dianne advising "you shouldn't put a SurfaceView inside of a ScrollView or other such container" (however, I note that was in response to someone wanting to scroll a SurfaceView that occupied more than the screen area). I did, however, find that a test Activity using a HorizontalScrollView with several SurfaceViews contained within did seem to work fine; I was able to scroll left and right to be able to view all SurfaceViews and they continued to redraw okay. So, to round up the question (and apologies for hijacking the OP's original thread slightly): in order to implement a layout that's larger than the screen size where the user scrolls back and forth to see all content, and where some of the screen components to be scrolled are implemented using SurfaceViews, what View mechanisms and / or ViewGroup derivatives should one *not* be using? Apologies in advance if I've misquoted or got the wrong end of the stick at all. Many thanks, Trev On Sep 21, 7:13 pm, MobileVisuals <[email protected]> wrote: > I got this to work no without the ViewFlipper. I think that there > should be information in the ViewFlipper class > that it doesn't support SurfaceView. I lost many hours of work because > of this. The reason I used the ViewFlipper class for SurfaceView was > that other threads on this forum recommended it, like this one: > > https://groups.google.com/group/android-developers/browse_thread/thre... > > So there are other developers who have made the same mistake. > > On Sep 20, 3:51 pm, MobileVisuals <[email protected]> wrote: > > > How can I then switch between a view with 2d rendering and a view with > > 3d rendering? > > > I suppose I have to use GLSurfaceView for 3d rendering with OpenGL? > > > On Sep 20, 3:00 pm, Jens <[email protected]> wrote: > > > > That would be the gist of what both Dianne & Romain Guy said yes. > > > > On Sep 20, 2:13 pm, MobileVisuals <[email protected]> wrote: > > > > > GLSurfaceView extends SurfaceView. Does that mean that it is not > > > > possible to animate GLSurfaceView with a viewflipper? > > > > > On Sep 20, 9:54 am, Romain Guy <[email protected]> wrote: > > > > > > You can animate another view on top of a SurfaceView, you just cannot > > > > > animate the SurfaceView itself. > > > > > > On Tue, Sep 20, 2011 at 12:51 AM, MobileVisuals > > > > > <[email protected]>wrote: > > > > > > > Thanks for the info, I have spent many hours investigating this > > > > > > issue > > > > > > and now I finally know what the problem is. My app has a standard 2d > > > > > > menu. It is possible to view different 3d visual effects from the > > > > > > menu. The 3d visual effects are rendered in a GLSurfaceView. That > > > > > > class extends SurfaceView. > > > > > > > You say that SurfaceView should not be used in a ViewFlipper. How > > > > > > can > > > > > > I implement my app if I can't use SurfaceView or GLSurfaceView? > > > > > > Which > > > > > > type of view should I use for the ViewFlipper? Can I render the 3d > > > > > > visual effects with other views than GLSurfaceView? > > > > > > > Or shouldn't I use a ViewFlipper at all? If not, how can I then > > > > > > switch > > > > > > between the 2d and the 3d rendering? > > > > > > > On Sep 19, 7:37 pm, Dianne Hackborn <[email protected]> wrote: > > > > > > > Don't use a SurfaceView in a ViewFlipper. > > > > > > > > Nor a ListView. > > > > > > > > SurfaceView is a *very* *special* view. As it says, what it does > > > > > > > is > > > > > > create > > > > > > > a completely separate surface (a.k.a. window) that is associated > > > > > > > with > > > > > > your > > > > > > > main window. This window is positioned behind the main window, > > > > > > > and a > > > > > > hole > > > > > > > punched through your main window to see the surface behind. > > > > > > > > By its nature, this makes the interaction between the surface of > > > > > > > the > > > > > > surface > > > > > > > view and the main view hierarchy limited. > > > > > > > > The purpose of SurfaceView is to present static things like video > > > > > > playback > > > > > > > or a game playfield in its own surface so that it can draw > > > > > > > outside of the > > > > > > > normal view hierarchy update model (and use OpenGL drawing, > > > > > > > different > > > > > > color > > > > > > > spaces, etc). It is not to give a tight integration with the > > > > > > > rest of the > > > > > > > view hierarchy. > > > > > > > > You should essentially think of it as an overlay, because really > > > > > > > that is > > > > > > > what it is. > > > > > > > > On Mon, Sep 19, 2011 at 10:29 AM, MobileVisuals < > > > > > > [email protected]>wrote: > > > > > > > > > My app uses a ViewFlipper. It is possible to flip between the > > > > > > > > views > > > > > > > > without problems at first.But after switching to another app > > > > > > > > and then > > > > > > > > switching back to the ViewFlipper app, it is not possible to > > > > > > > > flip > > > > > > > > between the views. One of the views is always displayed as just > > > > > > > > a > > > > > > > > black screen. > > > > > > > > > I have investigated the reason for this, using the simplest > > > > > > > > possible > > > > > > > > SurfaceView. It is still the same problem. > > > > > > > > It is not a thread problem, I see that the onDraw method is > > > > > > > > called > > > > > > > > like it should. What is the reason for this? Doesn't the > > > > > > > > ViewFlipper > > > > > > > > class support SurfaceView like it should? > > > > > > > > > I got the code for the SurfaceView from the basic tuturial: > > > > > > > > >http://www.edu4java.com/androidgame/androidgame2.html > > > > > > > > > and the code for the View flipper from Mark Murphys View flipper > > > > > > > > tutorial: > > > > > > > > >https://github.com/commonsguy/cw-android/tree/master/Fancy/Flipper1 > > > > > > > > > This is my code: > > > > > > > > ----------------------------- > > > > > > > > > public class FlipperDemo2 extends Activity { > > > > > > > > > ViewFlipper flipper; > > > > > > > > > @Override > > > > > > > > public void onCreate(Bundle icicle) { > > > > > > > > super.onCreate(icicle); > > > > > > > > setContentView(R.layout.main); > > > > > > > > > flipper=(ViewFlipper)findViewById(R.id.details); > > > > > > > > GameView lv=new GameView(this.getApplicationContext(),true); > > > > > > > > flipper.addView(lv, > > > > > > > > new ViewGroup.LayoutParams( > > > > > > > > ViewGroup.LayoutParams.FILL_PARENT, > > > > > > > > ViewGroup.LayoutParams.FILL_PARENT)); > > > > > > > > GameView lv2=new GameView(this.getApplicationContext(),false); > > > > > > > > flipper.addView(lv2, > > > > > > > > new ViewGroup.LayoutParams( > > > > > > > > ViewGroup.LayoutParams.FILL_PARENT, > > > > > > > > ViewGroup.LayoutParams.FILL_PARENT)); > > > > > > > > flipper.setFlipInterval(2000);//2000 > > > > > > > > flipper.startFlipping(); > > > > > > > > } > > > > > > > > } > > > > > > > > ---------------------------------- > > > > > > > > > public class GameView extends SurfaceView { > > > > > > > > > private SurfaceHolder holder; > > > > > > > > boolean blue; > > > > > > > > > public GameView(Context context,boolean _blue) { > > > > > > > > > super(context); > > > > > > > > holder = getHolder(); > > > > > > > > blue=_blue; > > > > > > > > holder.addCallback(new SurfaceHolder.Callback() { > > > > > > > > > @Override > > > > > > > > public void surfaceDestroyed(SurfaceHolder > > > > > > > > holder) { > > > > > > > > > } > > > > > > > > > @Override > > > > > > > > public void surfaceCreated(SurfaceHolder > > > > > > > > holder) { > > > > > > > > > Canvas c = holder.lockCanvas(null); > > > > > > > > onDraw(c); > > > > > > > > holder.unlockCanvasAndPost(c); > > > > > > > > > } > > > > > > > > > @Override > > > > > > > > public void surfaceChanged(SurfaceHolder > > > > > > > > holder, int > > > > > > > > format, int width, int height) { > > > > > > > > } }); > > > > > > > > } > > > > > > > > > @Override > > > > > > > > > protected void onDraw(Canvas canvas) { > > > > > > > > > if(blue) > > > > > > > > canvas.drawColor(Color.YELLOW); > > > > > > > > else > > > > > > > > canvas.drawColor(Color.GREEN); > > > > > > > > } > > > > > > > > > } > > > > > > > > > -- > > > > > > > > You received this message because you are subscribed to the > > > > > > > > Google > > > > > > > > Groups "Android Developers" group. > > > > > > > > To post to this group, send email to > > > > > > [email protected] > > > > > > > > To unsubscribe from this group, send email to > > > > > > > > [email protected] > > > > > > > > For more options, visit this group at > > > > > > > >http://groups.google.com/group/android-developers?hl=en > > > > > > > > -- > > > > > > > Dianne Hackborn > > > > > > > Android framework engineer > > > > > > > [email protected] > > > > > > > > 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 > > > > > > [email protected] > > > > > > To unsubscribe from this group, send email to > > > > > > [email protected] > > > > > > For more options, visit this group at > > > > > >http://groups.google.com/group/android-developers?hl=en > > > > > > -- > > > > > Romain Guy > > > > > Android framework engineer > > > > > [email protected] -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

