I need to raise the activation up by 15% of the height of the screen (regardless of which screen, the element should rise by 15%) beyond the screen's visibility ... I do it this way
Here I have a custom view
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> /.../ <com.example.android.camera2basic.AutoFitTextureView android:id="@+id/texture" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentBottom="false" android:layout_alignParentStart="true"> </com.example.android.camera2basic.AutoFitTextureView> /.../ </RelativeLayout> here I set the parameters to do it
private void initVar() { // Margin set in % of the screen int marginLeft = 0; ------> int marginTop = 15; вот здесь я указываю процент от высоты экрана int marginRight = 0; int marginBottom = 0; // Здесь мы получаем высоту и ширину экрана Display display = getWindowManager().getDefaultDisplay(); Point size = new Point(); display.getSize(size); screenWidth = size.x; screenHeight = size.y; // Здесь мы устанавливаем параметры для нашего вью RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); param.setMargins((screenHeight * marginLeft) / 100, -((screenHeight * marginTop) / 100), (screenHeight * marginRight) / 100, (screenHeight * marginBottom) / 100); mTextureView = (AutoFitTextureView) findViewById(R.id.texture); mTextureView.setLayoutParams(param); and this is what happens when I upload this whole thing to the Samsung S5 1980x1080, then it looks like I’m counting, exactly 15% is busy (the white bar below is the default color of the screen that opens when we twist the view)
But when I upload the same project to the 1280x800 emulator, then for some reason the screen does not rise by 15% but by 25-30% (definitely not by 15%)
And if you try on an emulator with a resolution of 1440 * 2560, it turns out like this
In the first screenshot, the white bar does not reach the inscription "Front picture", and in the second it captures it and even more, and on the third it is generally 50% of the screen ...
Very strange it turns out because the formula for which the calculation is made implies that I take the height of the screen and get exactly 15% from it ...
Why on one device is 15%, and on the other it is more and on the third it is generally 50% of the screen
What am I doing wrong??
Here is a screenshot of which the margin set to 0 and there should not be a white band on the screen, but it is there, although it does not exist on a real device ...




PercentRelativeLayoutclass and support: percent support library - it allows you to set dimensions directly in percent, maybe it will help you. - pavlofffAutoFitTextureViewto display the image from the camera on the screen, which automatically selects the best sizes and aspect ratios for myself and when the sizes are dynamically calculated, then the preview (picture) from the camera is set ... I think that the whole problem is that withAutoFitTextureViewat a screen resolution of 2550 * 1280, it simply cannot evenly stretch to the full extent while maintaining the correct aspect ratio ... What do you think? Could this be right? I don’t know how to test this truth ... - Aleksey Timoshchenko