Bug 22950 - Different rendering behaviour on platforms using relative layout
Summary: Different rendering behaviour on platforms using relative layout
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.2.3
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2014-09-12 14:38 UTC by Kent Green [MSFT]
Modified: 2014-09-23 10:34 UTC (History)
5 users (show)

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

Sample to reproduce the bug (4.96 MB, application/zip)
2014-09-12 14:38 UTC, Kent Green [MSFT]

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 on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Kent Green [MSFT] 2014-09-12 14:38:47 UTC
Created attachment 8042 [details]
Sample to reproduce the bug

This issue was reported by a customer in the following case:

Using the attached sample, I'm able to confirm the display is working incorrectly as shown in the image for Android. (though due to my setup I'm not currently able to test for iOS or WinPhone.)

--Screenshots sent by the customer:
Android (incorrect):
http://www.screencast.com/t/FKl4AHuy (This is the same as what I see when testing in Android)

iOS (incorrect):

WinPhone (correct):

---My Build Information---

=== Xamarin Studio ===

Version 5.4 (build 216)
Installation UUID: 8ef63a7c-1b18-40de-a334-7f78777fcb55
	Mono 3.8.0 ((no/45d0ba1)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 308000009

=== Apple Developer Tools ===

Xcode 5.1.1 (5085)
Build 5B1008

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: 436246d
Build date: 2014-09-10 00:04:26-0400

=== Xamarin.Mac ===

Version: (Business Edition)

=== Xamarin.Android ===

Version: 4.16.0 (Business Edition)
Android SDK: /Users/kentgreen/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		4.0   (API level 14)
		4.0.3 (API level 15)
		4.4   (API level 19)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-466.1-11M4716)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-466.1, mixed mode)

=== Build Information ===

Release ID: 504000216
Git revision: bf73535e350da9a84b6990c72149b84467757c52
Build date: 2014-09-09 15:40:19-04
Xamarin addins: cb699c7d52f13def4e9746f8086e9f24ef6d894f

=== Operating System ===

Mac OS X 10.9.4
Darwin Kents-MacBook-Pro.local 13.3.0 Darwin Kernel Version 13.3.0
    Tue Jun  3 21:27:35 PDT 2014
    root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64

---Additional information:---
I've asked the customer to also send their build information and Xamarin.Forms version as confirmation; and I will add a comment regarding it when they respond.
Comment 1 Yuri 2014-09-12 14:42:35 UTC
The follow version is used
<package id="Xamarin.Forms" version="" targetFramework="portable-net45+win+wp80+MonoAndroid10+MonoTouch10" />
Comment 2 Arpit Jha 2014-09-15 07:47:02 UTC
I have checked this issue and able to reproduce it with the help of bug description.

I observed that rendering behavior diffrent on platforms using relative layout. 

Screencast regarding same :

http://www.screencast.com/t/cEgLEimL4cQ (Android)

http://screencast.com/t/Ykt8LzEECsU (ios)


Environment Info:
VS professional 2013 Update3
Android Device( Samsung SGH 1747)
Comment 3 Jason Smith [MSFT] 2014-09-23 01:17:05 UTC
This is not a bug but a misunderstanding of the API. You cannot depend on the Height/Width of an object being already set in the resolution of its size constraints. To get the desired height you need to actually measure it. I have updated your class as follows to do that:

public class MainPage : ContentPage
        Label l, l1, l2, l3, l4;
        StackLayout sl, sl1;
        RelativeLayout sMain;

        public MainPage()
            l = new Label
                Text = "I am in Main",
                BackgroundColor = Color.Green
            l1 = new Label
                Text = "I am in top",
                BackgroundColor = Color.Red

            sMain = new RelativeLayout()
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions = LayoutOptions.FillAndExpand,
                BackgroundColor = Color.Gray,

                    Constraint.RelativeToParent((parent) =>
                        return parent.Height / 2;
                Constraint.RelativeToView(l, (parent, sibling) =>
                    return sibling.X + sibling.Width;
                Constraint.RelativeToView(l, (parent, sibling) =>
                    return sibling.Y - l.GetSizeRequest (double.PositiveInfinity, double.PositiveInfinity).Request.Height;

			l1.GestureRecognizers.Add (new TapGestureRecognizer(v => {
				l4_Clicked (null, null);

            l2 = new Label
                Text = "I am in bottom",
                BackgroundColor = Color.Blue
            l3 = new Label
                Text = "I am even lower",
                BackgroundColor = Color.Yellow,
                TextColor = Color.Black
            sl = new StackLayout()
                Spacing = 0

                    Constraint.RelativeToParent((parent) =>
                        return parent.Height - sl.GetSizeRequest (double.PositiveInfinity, double.PositiveInfinity).Request.Height;

            sl1 = new StackLayout()
                Spacing = 0,
                Padding = 0,
                BackgroundColor = Color.Maroon
            var l4 = new Button
                Text = "Evenly spaced",
                BackgroundColor = Color.Yellow,
                TextColor = Color.Black,
            l4.Clicked += l4_Clicked;
                    Constraint.RelativeToView(sl, (parent, sibling) =>
                        Debug.WriteLine("Calculated: " + (sibling.Y - sibling.Height));
                        return sibling.Y - sl1.GetSizeRequest (double.PositiveInfinity, double.PositiveInfinity).Request.Height;

            Content = sMain;



        void l4_Clicked(object sender, EventArgs e)
            Debug.WriteLine("Form: " + sMain.Bounds);
            Debug.WriteLine("Sl: " + sl.Bounds);
            Debug.WriteLine("Sl1: " + sl1.Bounds);

Comment 4 Yuri 2014-09-23 10:34:44 UTC
Why does it work on Windows Phone? While debugging an app I saw that this calculation of constraints was called few times and eventually on Windows Phone the size was correct without me requesting size explicitly. Can the same be done on other platforms?