Search code examples
javaandroidimageviewsurfaceviewimplements

Implement a ImageView to a SurfaceView


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.


Solution

  • 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);