子类SurfaceView和覆盖的OnDraw()来改变SurfaceView参数来生成所需大小的preVIEW [英] subclassing SurfaceView and overriding onDraw() to change SurfaceView parameters to generate preview of desired size

查看:399
本文介绍了子类SurfaceView和覆盖的OnDraw()来改变SurfaceView参数来生成所需大小的preVIEW的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经子类的SurfaceView和实例化在活动中的onCreate。将生成preVIEW但控制从未进入的OnDraw(),它重写的SurfaceView的子类。这是为什么呢?

I have subclassed the SurfaceView and instantiating it in onCreate of the Activity. The preview is generated but the control never enters onDraw() which is overriden in the subclass of SurfaceView. Why is that?

class ActivityClass extends Activity{

    onCreate(){

        mPreview = new Preview(this);
        setContentView(mPreview);
    }
    public void startPreview(){

        rec = new MediaRecorder();
        rec.setVideoSource();.......
        rec.setPreviewDisplay(mPreview.getSurfaceHolder.getSurface());
    } 
}

class Preview extends SurfaceView implements SurfaceHolder.Callback{

    SurfaceHolder mHolder;

    public Preview(Context context){
        super(context);
        mHolder = getHolder();     
        mHolder.addCallback(this);      
        mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); 
        bringToFront();//this is not
        invalidate();//making a difference
    }

    SurfaceHolder getSurfaceHolder(){

        return mHolder;
    }
    //Surface callback methods implemented here
}

绘制preVIEW在表面之前,不应该控制被提供给OnDraw的回调,如果它被实现?

Before drawing the preview on the Surface, shouldn't the control be given to the onDraw callback if it is implemented?

由于OnDraw的回调称的Andr​​oid框架你不画的看法。我会画它,因为我已经实现。我对吗?

Because onDraw callback says to the Android framework 'you don't draw the view. I will draw it since I have been implemented'. Am I right?

那么,为什么在控制未能进入的OnDraw()?请大家帮帮忙。

Why then, is the control failing to enter onDraw()? Please help.

推荐答案

您只需添加

setWillNotDraw(false)

要构造。

和它做..:)

这篇关于子类SurfaceView和覆盖的OnDraw()来改变SurfaceView参数来生成所需大小的preVIEW的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆