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

enter image description here

And on the Meizu MX5 and another Chinese, this picture turns out to be half the screen

like this

enter image description here

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?

  • It seems to me, at first glance, that the problem is not that the picture is on the half of the screen, but in some default parameters that are responsible for the content’s “fits” into the widget on these devices, which differ from those used in android. That is, in the first screenshot, the height is filled (to include 100% of the height, and cut to the width), in the second - to the width (to include 100% of the width, and the height is proportional to the proportions.). - pavlofff
  • Just that I measured the width of the screen and the width of AutoFitTextureView it 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 Timoshchenko
  • Well, if you place an image in the ImageView widget 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. - pavlofff
  • @pavlofff aa I understood ... But I have a specific custom class that should work for everyone equally ... Strange of course it turns out ... - Aleksey Timoshchenko
  • Well, this is not your class, but inherited from TextureView and 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

0