简体   繁体   中英

Android layout is bigger than screen

My problem is that components inside a ConstraintLayout spill out of the screen. My app has always worked and I have not made changes to these layouts recently. Now, buttons and views are shifted right and down. The constraints on the components act as if the layout was larger. Suddenly, this problem appeared on an S10, an S9 and an A70 without the app having been updated.

Screenchot of the bug

在此处输入图片说明

Screenshot of the normal screen

在此处输入图片说明

After taking a screenshot, the layout somewhat comes back to its normal state

在此处输入图片说明

The play button is supposed to be centered in x and y. The constraint are all at 0 with the parent view. The remove ads button is constrained left and right equally and from the top only. The array of buttons at the bottom are all within a view, which is constrained equally on the left and right and only from the bottom.

One thing that I noticed is that on my S10, the display settings are either 3040x1440 or 2280x1080. I currently have it set to 3040x1440. It seems like the components are shifted right just enough to fit as if they were in the center of the 3040x1440, but we are only seeing the first 2280x1080 pixels of the screen.

This problem also coincides with the fact that the app now appears with the gaming navigation bar at the bottom. I have never seen my app with this navigation bar before. On the three phones that exhibit this problem, the gaming navbar had never appeared before now and the problem started happening as soon as the bar was introduced. I did not have control over this.

One way I am able to come back to my desired normal layout is by quitting the app and coming back to the app through recently opened apps or via the app icon. Then, the layout is normal until I change activity. Then, the next activity is also spilling out.

All the activities in the app are set to "portrait" in the manifest. All my activities use a ConstraintLayout as their main layout, but not all activities experience this problem.

When that bug was first reported, I tried to reproduce it. The only way I was able to reproduce the bug was by having the app open in split-screen, opening a second app, turning the device sideways to landscape mode and then closing the second app by extending my app. The fact that the phone went from landscape to portrait and fullscreen made it exhibit the comportment you see here.

I think this has to do with the gaming navbar being updated because literally nothing changed in the app between yesterday and today and now this problem exists.

What I tried:

I tried to not hide the navbar and not make the app fullscreen by commenting this code:

        View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

This did not work, the gaming navbar was present and the UI was still spilling out.

Since, the problem seemed to come from the fact tha tthe app thought it was horizontal, I tried adding this to the affected activities:

        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

This did not work however.

One activity that experiences this bug doesn't have more UI related code than what is shown here, so I don't think the bug is in my code as the app has worked for months.

I have resolved my issue. Somewhat, my app was using a beta version of the ConstraintLayout.

I simply changed my dependencies from:

implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'

With the most recent version of ConstraintLayout found here , which is:

implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM