Bug 36932 - Items in a Grid are frequently positioned wrong by one or more pixels
Summary: Items in a Grid are frequently positioned wrong by one or more pixels
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.0.0
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2015-12-12 01:03 UTC by bobme981
Modified: 2017-07-01 17:49 UTC (History)
6 users (show)

Tags: ac
Is this bug a regression?: ---
Last known good build:

sample app and screenshots (19.50 KB, application/x-zip-compressed)
2015-12-12 01:03 UTC, bobme981

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report for Bug 36932 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description bobme981 2015-12-12 01:03:47 UTC
Created attachment 14258 [details]
sample app and screenshots

In a fairly simple Grid it is not very difficult to get the layout of the child items to be off by one or more pixels. The results seem to vary by device, too. 

The case shown by the attached sample app involves two horizontal StackLayouts in the same Grid column that *should* be right-aligned instead have their right edges visually offset by 1 px. This seems to be related to the fact that StackLayout.Spacing is set to a non-integer value (7.5). If you step through the code you can see that the Bounds.Right properties of the two StackLayouts are indeed offset by exactly 0.5.

The second case is actually device specific. On a 7" KitKat (4.4) XHDPI Tablet (1920x1200) running in the VS Emulator for Android, the grid elements along the bottom edge are all aligned. On a Kindle Fire HD (1280x800), the grid elements are not aligned. (see screenshots)

In the full app I am working on I have also seen a case where the right-most element in a StackLayout ends up positioned 1 px short of the right edge of the StackLayout, for no obvious reason. In that same case the two StackLayouts right-aligned in the Grid column were visually offset by 2 px.

This is really frustrating when trying to use Grids and StackLayouts to lay things out precisely on the screen. The layouts in the sample app are very simple with just a few Grid rows/cols and integer dimensions for almost everything. I would expect maybe a few extremely tiny rounding errors as a result of all layout properties being represented as doubles, but actually generating layouts with values apparently rounded somewhere along the way to the nearest whole integer is a serious problem.

Really need this stuff to work... :(
Comment 1 Arpit Jha 2016-01-14 06:23:27 UTC
I have checked this issue with Xamarin.Forms. and also getting same behaviour mentioned in bug description.

Screencast: http://www.screencast.com/t/ecuDnX8J9az4
adb logcat: https://gist.github.com/Arpit360/e4112148ce506e208c2c

Environment Info:
Microsoft Visual Studio Professional 2013
Version 12.0.40629.00 Update 5
Microsoft .NET Framework
Version 4.5.51641

Installed Version: Professional

Xamarin (21aad62)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android (50280e4)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.iOS (122b860)
Visual Studio extension to enable development for Xamarin.iOS.
Comment 2 Chris King 2016-12-22 21:14:39 UTC
Re-confirmed on XHDPI Lollipop 5.0 Emulator Api 21 on master; box is off by a pixel
Comment 3 Joel Day 2017-07-01 17:49:13 UTC
This is still a problem in 2.3.x. Would at least like a workaround.