How do you crop (not scale) a PreviewView
so that it always fits the given parent ViewGroup
? See a demo I created here.
In the below example, there are two equal size PreviewView
s. Both PreviewView
s extend their parent bounds because the selected resolution's height is greater than the container.
The scale types defined in PreviewView.ScaleType
will just resize the frame, adding black borders on both sides, maintaining the aspect ratio.
My device (Pixel 4XL) doesn't have a supported resolution that fits nicely into these frames, so I'd like to use a resolution that's larger than the given frame, and crop the excess.
I know that setTargetResolution
is supposed to return a resolution that is a minimum of the bounds given, so I could pass the parent width/height, but this still doesn't guarantee that PreviewView
stays within bounds.