以下是SurfaceView子类中的重写dispatchDraw。我正在尝试更改Surface的参数(仅获取视频预览的子部分。
@Override
public void dispatchDraw (Canvas canvas) {
Log.d(TAG,"**************inside dispatchDraw************");
int VIEW_WIDTH = canvas.getWidth();
int VIEW_HEIGHT = canvas.getHeight();
Log.d(TAG,"**************inside dispatchDraw************" + Integer.toString(VIEW_WIDTH) + " ," + Integer.toString(VIEW_HEIGHT));
int newWidth = 400;
int newHeight = 240;
float scaleWidth = ((float) newWidth) / VIEW_WIDTH;
float scaleHeight = ((float) newHeight) / VIEW_HEIGHT;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
canvas.setMatrix(matrix);
super.dispatchDraw(canvas);
Log.d(TAG,"**************inside dispatchDraw-after super************");
}
为什么上面的代码根本不会改变SurfaceView的尺寸?
答案 0 :(得分:1)
因为SurfaceView不使用视图层次结构的Canvas来绘制。