Android: Margins respond to taps. Portrait orientation app and horizontal tablet

37 Views Asked by At

I am developing an Android app in kotlin. I am trying to create an app with a fixed portrait orientation (landscape not supported).

In the Android project creation, I selected "Basic Views Activity" and added the following code.

AndroidManifest.xml

<application
    android:screenOrientation="portrait"
    android:configChanges="orientation|screenSize"
    

MainActivity.kt

 override fun onCreate(savedInstanceState: Bundle?) {
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

It works fine on my smartphone, but when I run it on my tablet, strange things happen.

When the screen is turned horizontally, a black area is created on the left and right sides, and a vertical screen appears in the center.

At this time, tapping the black areas on the left and right will cause the inside of the screen to behave as if it were pressed.

Although it is not actually visible, the screen expands to the left and right, and the area of the buttons seems to expand as well.

Is there any way to make the black areas on the left and right not respond when tapped?

enter image description here

0

There are 0 best solutions below