W
W
Wiemo2012-10-04 19:43:36
Android
Wiemo, 2012-10-04 19:43:36

SurfaceView in layout?

Such question:
Described Surface in layout.

<SurfaceView
android:id="@+id/surfaceView1"
android:layout_width="wrap_content"
android:layout_height="match_parent"  />

How can I bind my class to it now?
In the examples, the surfaceview is called through the main activity class.
setContentView(new MySurfaceView(this));
But I already have a SurfaceView in the layout, so I call:
setContentView(R.layout.activity_main);

Answer the question

In order to leave comments, you need to log in

4 answer(s)
P
palmut, 2012-10-04
@palmut

Is it

SurfaceView view = (SurfaceView) findViewById(R.id.surfaceView1); 

won't work?

L
LeoCcoder, 2012-10-04
@LeoCcoder

It is clear that this will not work. Here is how to do it right: stackoverflow.com/questions/5203547/draw-surfaceview-from-layout-xml

W
Wiemo, 2012-10-04
@Wiemo

does not work. More precisely, an empty surface view appears, the code from the class is not processed

W
Wiemo, 2012-10-04
@Wiemo

Thanks, that's what you need.
Moreover, the second parameter had to be added to the class MySurfaceViewin the subclass , in addition to . Well, actually this is clearly indicated in the link provided, otherwise fatal exception. The question is why is that? is called directly, and not through , then the class description without rolls. MySurfaceViewattributeSetcontext
Если surfaceviewlayoutattributeSet

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question