This situation ... I display the image from the camera in the AutoFitTextureView is a custom view that takes a picture for display
here is the code
public class AutoFitTextureView extends TextureView { private int mRatioWidth = 0; private int mRatioHeight = 0; public AutoFitTextureView(Context context) { this(context, null); } public AutoFitTextureView(Context context, AttributeSet attrs) { this(context, attrs, 0); } public AutoFitTextureView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } /** * Sets the aspect ratio for this view. The size of the view will be measured based on the ratio * calculated from the parameters. Note that the actual sizes of parameters don't matter, that * is, calling setAspectRatio(2, 3) and setAspectRatio(4, 6) make the same result. * * @param width Relative horizontal size * @param height Relative vertical size */ public void setAspectRatio(int width, int height) { if (width < 0 || height < 0) { throw new IllegalArgumentException("Size cannot be negative."); } mRatioWidth = width; mRatioHeight = height; requestLayout(); } @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); } } } } On one Samsung S5 device, this picture is perfect.
Here is a photo
And on the Meizu MX5 and another Chinese, this picture turns out to be half the screen
like this
I tried to display the height of the device screen and the height of the AutoFitTextureView after creating it on two devices
This is how I get the height of the AutoFitTextureView after it is created.
final AutoFitTextureView autoFitTextureView = (AutoFitTextureView) findViewById(R.id.autoFitTextureView); autoFitTextureView.post(new Runnable() { @Override public void run() { Log.e(MY_LOG, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! autoFitTextureView " + autoFitTextureView.getHeight()); } }); and that's how I get the height of the screen
/** * get a height of the screen **/ public static int getHeight(Activity act) { DisplayMetrics displaymetrics = new DisplayMetrics(); act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); return displaymetrics.heightPixels; } indicators such
on Samsung S5 :
E / CameraActivity: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! getHeight () 1920
E / CameraActivity: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! autoFitTextureView 1920
and on the Meizu MX5 like this
E / CameraActivity: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! getHeight () 1920
E / CameraActivity: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! autoFitTextureView 1920
This means that the devices have the same height of screens and the AutoFitTextureView that on one other device is stretched equally on the whole screen ...
Why then on the Samsung picture as it should be and on Meizu and another Chinese picture on the floor of the screen ???
What am I doing wrong?


AutoFitTextureViewit is the same 1080 ... So I did not fully understand, based on your words, where should I look? How to measure it in order to see the difference in numbers? otherwise it turns out that everything is the same, but in fact it does not ... - Aleksey TimoshchenkoImageViewwidget that is larger than the widget's size, then there are many values ​​of the crop parameter, how to fit it: in the center without resizing (which will go into the window, the rest is cut off), entirely along the vertical axis, entirely horizontally, on any axis, but to include the entire image, and so on. - here maybe the same thing happens. - pavlofffTextureViewand you redefine only a very small part of all its functionality. All that I have said is only an assumption, just from the screenshots it is very similar that this is exactly what is happening. - pavlofff 2:01 pm