0
votes

On my Moto E, I want my preview to be full screen hence i have set the texture view's dimension to be full screen i.e. 540*960by overriding onMeasure, but using camera2 api the closest match of preview size that i am getting is 768*432 which is of the same aspect ratio. Google sample suggests that "Initially, output stream images from the Camera2 API will be rotated to the native device orientation from the sensor's orientation, and the TextureView will default to scaling these buffers to fill it's view bounds. If the aspect ratios and relative orientations are correct, this is fine." But even when in native orientation I am getting stretched previews. Even if I setTransform to Identity matrix, I don't know how the preview is still scaled automatically to fill the whole screen.

1

1 Answers

0
votes

I also encountered this problem and solved it like this:

re-set surfaceview params (width and heigth).

ViewTreeObserver observer = mSurfaceView.getViewTreeObserver();
observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() 
{
    @Override
    public void onGlobalLayout() 
    {
        FrameLayout.LayoutParams surfaceParams = (FrameLayout.LayoutParams) mSurfaceView.getLayoutParams();
        surfaceParams.height = screenHeight;
        surfaceParams.width = screenWidth;
        mSurfaceView.setLayoutParams(surfaceParams);

        mSurfaceView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
    }
});