How can I make a SurfaceView larger than the screen?

前端 未结 4 958
清酒与你
清酒与你 2021-01-02 00:25

I would like to effectively make a simple digital zoom for the camera preview, so I thought I would simply resize my SurfaceView to be larger than the screen. Other questio

4条回答
  •  孤独总比滥情好
    2021-01-02 01:06

    What you can do is to get the window and set its height:

    getWindow().setLayout(1000, 1000);
    

    This makes your window larger than the screen making your root view and consequently your surfaceview, probably contained inside a Framelayout larger than screen.

    This worked for me let me know.

    The above would work no matter what. What you would want to do is listen for onSurfaceCreated event for your surface view. Then after you have the started the camera view and you are able to calculate size of your widget holding the preview, you would want to change size of the container widget.

    The concept is your container widget (probably FrameLayout) wants to grow larger than screen. The screen itself is restricted by the activity so first set size of your window,

    then set size of your framelayout (it would always be shrunk to max size of windows, so set accordingly).

    I do all this logic after my onSurfaceCreated is finished I have started the preview. I listen for this event in my activity by implementing a small interface, as my Camera preview is a separate class.

    Working on all API level >= 8

提交回复
热议问题