我在画布上使用SurfaceView
. 用户完成后如何定义取消surfaceView的方法?下面是我的 SurfaceView 实现。该类DrawOnTop
具有onDraw()
但我初始化了类中的所有变量Preview
。
public class Preview extends SurfaceView implements SurfaceHolder.Callback {
SurfaceHolder mHolder;
DrawOnTop mDrawOnTop;
boolean mFinished;
Preview(Context context, DrawOnTop drawOnTop) {
super(context);
mDrawOnTop = drawOnTop;
mFinished = false;
// Install a SurfaceHolder.Callback so we get notified when the
// underlying surface is created and destroyed.
mHolder = getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
public void surfaceCreated(SurfaceHolder holder) {
//I set the bitmaps etc here
mDrawOnTop.mBitmap = Bitmap.createBitmap(mDrawOnTop.mImageWidth,
mDrawOnTop.mImageHeight, Bitmap.Config.ARGB_8888);
mDrawOnTop.mBitmap.setPixels(mDrawOnTop.mRGBData, 0,
mDrawOnTop.mImageWidth, 0, 0, mDrawOnTop.mImageWidth,
mDrawOnTop.mImageHeight);
Button x = new Button(getContext());
x.setText("Hi");
x.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
mDrawOnTop.invalidate();
}
public void surfaceDestroyed(SurfaceHolder holder) {
mFinished = true;
}
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
}
}
编辑:
现在经过一些研究,我发现我需要使用 setContentView 并将其设置回我想要的活动。