Bug 40092 - AbsoluteLayout content does not fill all available space on some devices
Summary: AbsoluteLayout content does not fill all available space on some devices
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms (show other bugs)
Version: 2.1.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2016-04-05 01:54 UTC by Nathan Williams
Modified: 2017-10-04 16:53 UTC (History)
6 users (show)

See Also:
Tags: Android ac fr
Is this bug a regression?: ---
Last known good build:

Solution reproducing the problem. (91.01 KB, application/zip)
2016-04-05 01:54 UTC, Nathan Williams

Description Nathan Williams 2016-04-05 01:54:53 UTC
Created attachment 15602 [details]
Solution reproducing the problem.

Given the following page layout for an application:

            AbsoluteLayout mainLayout = new AbsoluteLayout()
                BackgroundColor = Color.White

            MainPage = new ContentPage
                Content = mainLayout

            BoxView view = new BoxView()
                Color = Color.Black
            mainLayout.Children.Add(view, new Rectangle(0, 0, 1, 1), AbsoluteLayoutFlags.All);

An approximately 1px border of white will be shown behind the BoxView, as the bounds for the BoxView are not calculated correctly for some devices.  The issue appears to be related to fractional "logical" bounds for the viewport, as devices which yield a whole number for Width and Height do not exhibit the problem, while those that have fractional bounds do.  For example, the Nexus 5 with a resolution of (1080 x 1776) and a density factor of 3 yields logical bounds of (360 x 592) and does **not** exhibit the problem, while the Nexus 6 with resolution of (1440 x 2392) and a density factor of 3.5 yields logical bounds of (411.42857143 x 683.42857143) and **does** exhibit the problem.

It would appear then that the problem is related to an integer truncation somewhere since instead of using:

mainLayout.Children.Add(view, new Rectangle(0, 0, 1, 1), AbsoluteLayoutFlags.All);

on the Nexus 6, I can use:

mainLayout.Children.Add(view, new Rectangle(0, 0, 411.42857143, 683.42857143), AbsoluteLayoutFlags.PositionProportional);

and the problem will **not** occur.

Attached is a solution reproducing the problem.
Comment 1 Matthew Percy 2017-05-22 03:55:40 UTC
I assume this hasn't been addressed yet?
Comment 2 Paul Vrugt 2017-09-05 13:47:47 UTC
any news on this? I'm running into the same problem. Any workaround available?
Comment 3 Nathan Williams 2017-09-05 14:00:52 UTC
The workaround that I use is to subclass AbsoluteLayout and override the ComputeLayoutForRegion method, using the exact same code as the Xamarin.Forms implementation but *without* the Math.Round calls.  I don't know if Xamarin had an explicit reason for rounding, but with this change, the content fills all available space.
Comment 4 Paul Vrugt 2017-09-05 14:02:40 UTC
Could you attach the workaround to the bug? Then I'll try and see if it fixes my issue too.
Comment 5 Brad Moore 2017-09-06 03:38:56 UTC
Nathan, how did you subclass and override ComputeLayoutForRegion its private?
Comment 6 Brad Moore 2017-09-06 05:13:09 UTC
I have added PR for this issue here, https://github.com/xamarin/Xamarin.Forms/pull/1128
Comment 7 Nathan Williams 2017-09-06 05:23:10 UTC
Brad, my mistake - I actually override LayoutChildren to call a re-implemented version of ComputeLayoutForRegion using the changes I described above.

Note You need to log in before you can comment on or make changes to this bug.