I worked with camera2 api demo from google and, unfortunately, the sample application was built to display the texture preview at about 70% of the screen height, after inspecting I was able to determine that this is due to the fact that AutoFitTextureView overrides the onMeasure() method, as shown below:
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); int width = MeasureSpec.getSize(widthMeasureSpec); int height = MeasureSpec.getSize(heightMeasureSpec); if (0 == mRatioWidth || 0 == mRatioHeight) { setMeasuredDimension(width, height); } else { if (width < height * mRatioWidth / mRatioHeight) { setMeasuredDimension(width, width * mRatioHeight / mRatioWidth); } else { setMeasuredDimension(height * mRatioWidth / mRatioHeight, height); } } }
I tried to fix this by setting the correct heights and widths in setMeasuredDimension(width, height); , this fixed a problem with the height and provided me with a full-screen preview from a texture image, however, the aspect ratio is completely broken and distorted on each device, what is the standard way to fix it? I see that many applications in the game store have found a way to solve this problem, but havent been able to track the fix, any help will go a long way, thanks.
source share