问题
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