我正在尝试使用SurfaceView小部件。我有一个班级
public class OurView extends SurfaceView implements Runnable {
public OurView(Context context) {
super(context);
Log.d("OurView", "Yay We started");
}
@Override
public void run() {
}
}
所以我在Activity的XML中有一个SurfaceView小部件。然后我尝试在onCreate
方法
TheView = (OurView) findViewById(R.id.theSurfaceView);
问题出在这里我收到错误,我无法将OurView
强制转换为android.view.SurfaceView
。
我知道我通常可以在onCreateMethod
TheView = new OurView(this);
setContentView(TheView);
事情是我不想这样做,我不想在我的整个活动上画画,我只想在我放在布局上的SurfaceView小部件上画画。我该怎么做?
答案 0 :(得分:3)
您应该将自定义的SurfaceView com.xx.OurView
放在布局中,而不是SurfaceView
。