0

I have one small question...

Is it possible to implement a ImageView inside a SurfaceView, or to create a ImageView inside the SurfaceView

And if so could someone point me in the right direction on how to do it.

Reno
  • 33,594
  • 11
  • 89
  • 102
Peter Dempsey
  • 485
  • 1
  • 9
  • 17

2 Answers2

3

No, you cannot add child Views to a SurfaceView.

You can put both an ImageView and a SurfaceView in some other container, and some containers (RelativeLayout, FrameLayout) allow later children to float over top of earlier children (Z-axis ordering). So, you can give the visual appearance of an ImageView in a SurfaceView that way.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Is there a way to do that in code I would appreciate your help. – Peter Dempsey Feb 15 '12 at 21:15
  • 1
    @toggy-tog-togs: Put the `SurfaceView` in the `RelativeLayout` in XML. Then, at runtime, just call `addView()` on the `RelativeLayout` to add your `ImageView`, using an appropriate `RelativeLayout.LayoutParams`. – CommonsWare Feb 15 '12 at 21:44
  • can you tell me how to handle click listener on the views which were added to the relative layout , because they are not clickable. – Reham Feb 08 '17 at 11:16
2

I did this in code with a TextView, but you could just change text view with ImageView.

My TextView is a small bar across the top, hence the changing parameters.

      params = new LinearLayout.LayoutParams(
               LinearLayout.LayoutParams.FILL_PARENT, 
           LinearLayout.LayoutParams.WRAP_CONTENT);

      LinearLayout layout = new LinearLayout(this);
      layout.setOrientation(LinearLayout.VERTICAL);

      TextView tv = new TextView(this);
      ourSurfaceView = new SurfGame(this);

        testbox = new LinearLayout.LayoutParams(widthx,heighty/30);
    layout.addView(tv,testbox);
    layout.addView(ourSurfaceView,params);
    setContentView(layout);
a54studio
  • 965
  • 11
  • 11