我已经实现了许多类似的活动,但由于某种原因,下面的类没有达到 onDraw 调用。(非常简单的)类:
import ...etc.
public class SVPlay extends SurfaceView implements Callback {
Context context;
Point screenSize;
Bitmap backGroundImage
public SVPlay(Context _context) {
super(_context);
context = _context;
this.getHolder().addCallback(this);
setFocusable(true);
screenSize = DrawUtil.getInstance(context).getScreenSize();
backgroundImage = BitmapFactory.decodeResource(context.getResources(), R.drawable.room);
backgroundImage = Bitmap.createScaledBitmap(backgroundImage, screenSize.x, screenSize.y, false);
}
@Override public boolean onTouchEvent(MotionEvent event) {
...
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(0xFFAAAAAA);
canvas.drawBitmap(backgroundImage, 0, 0, paint);
}
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
// TODO Auto-generated method stub
}
public void surfaceCreated(SurfaceHolder holder) {
setWillNotDraw(false);
}
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
}
}
此类由活动实例化并运行: public class PlayActivity extends Activity {
SVPlay svPlay;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
svPlay = new SVPlay(this);
setContentView(svPlay);
}
....
}
这类似于对我有用的任何其他活动/surfaceView 实现,但由于某种原因,未调用 onDraw。为了简化问题的代码,我消除了实际的绘图活动,并通过在 onDraw() 中设置断点进行测试。执行未到达 onDraw 调用。添加 postInvalidate() 调用没有帮助。构造函数被调用,并在没有任何问题或异常的情况下执行。到底是怎么回事?19/5/13 - 进一步调查。此活动/SurfaceView 在作为单独项目运行时显示,因此问题不在此处显示的代码中,而在调用活动的代码中。更多即将...