google / cameraview

[DEPRECATED] Easily integrate Camera features into your Android app
Apache License 2.0
4.74k stars 1.03k forks source link

Cameraview blacks out after changing its size #111

Open ankitbatra11 opened 7 years ago

ankitbatra11 commented 7 years ago

Hi,

cameraview blacks out after changing it's LayoutParams in an activity. Below piece of code used to work earlier before I updated to the latest changes:

public void applySize(int sizePixels) {
        if (cameraViewRef != null) {
            CameraView cameraView = cameraViewRef.get();
            if (cameraView != null) {
                ViewGroup.LayoutParams params = cameraView.getLayoutParams();
                if (params != null) {
                    params.width = sizePixels;
                    params.height = sizePixels;
                    cameraView.setLayoutParams(params);
                } else {
                    Timber.d("layout params are null for cameraview");
                }
            } else {
                Timber.d("camera view got GC'ed");
            }
        } else {
            Timber.e("must set a camera view");
        }
    }
mkotyk commented 7 years ago

I see that also when changing Visibility

FabinPaul commented 7 years ago

@mkotyk TextureView is added twice to CameraView. So when requestLayout is called on CameraView blank surface comes up. Note that CameraView parent is FrameLayout

csbz17027 commented 7 years ago

I met the same requirements and issues. You can replace the layout to achieve the effect.