Implement a ImageView to a SurfaceView

前提是你 提交于 2019-12-08 09:35:41

问题


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.


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/9285509/implement-a-imageview-to-a-surfaceview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!