自定义SurfaceView崩溃的应用程序

时间:2018-05-02 09:52:00

标签: android android-fragments surfaceview

我有一个自定义SurfaceView我希望显示在Fragment中显示,但是当我添加它时,应用程序崩溃了。

自定义SurfaceView代码如下:

public class CameraFocusIndacatorSurfaceView extends SurfaceView implements Runnable {

    private final Paint paint;
    private final SurfaceHolder mHolder;
    private final Context context;

    @Override
    public void run(){}

    public CameraFocusIndacatorSurfaceView(Context context) {
    super(context);
    mHolder = getHolder();
    this.context = context;
    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    init();
}           

    private void init(){
        mHolder.setFormat(PixelFormat.TRANSPARENT);
        paint.setColor(Color.WHITE);
        paint.setStyle(Paint.Style.STROKE);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        //do some stuff
    }
}

Fragment所在的SurfaceView中调用此行时,应用会崩溃:

View view = inflater.inflate(R.layout.fragment_attachment_upload_camera, container, false);

这是Fragment

的视图堆栈

enter image description here

构造函数没有被拾取,或者是什么?

0 个答案:

没有答案