Bug 20766 - Image AnchorX not working on Android
Summary: Image AnchorX not working on Android
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms (show other bugs)
Version: 1.0.6188
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2014-06-20 14:31 UTC by John Miller [MSFT]
Modified: 2015-08-11 14:15 UTC (History)
7 users (show)

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

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 John Miller [MSFT] 2014-06-20 14:31:58 UTC
Created attachment 7134 [details]

## Overview: 

    The attached test case defines an Image with XAML. The AnchorX attribute is not working when ran on Android. It does seem to work when running on iOS. 

## Steps to Reproduce: 

    1. Run the attached sample. 

## Actual Results: 

    The "verizon" logo is cutoff on the screen.

## Expected Results: 

    The "verizon" logo should be completely visible. Run on iOS to see the expected behavior. 

## Build Date & Platform: 


## Additional Information: 

    Relevant XAML is in the CarrierHeaderComponent.xaml file.
Comment 1 Udham Singh 2014-08-13 09:11:26 UTC
I have checked this issue and getting the same behaviour mentioned in bug description. To reproduce this issue I have followed the instructions mentioned in bug description.

Xamarin.Forms Version

Environment Info : 

=== Xamarin Studio ===

Version 5.2.1 (build 1)
Installation UUID: 952292e8-1484-4c56-b664-6ff701bef591
	Mono 3.6.0 ((no/f540f8a)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 306000039

=== Xamarin.Android ===

Version: 4.14.0 (Business Edition)
Android SDK: /Users/xamarin76/Desktop/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)
		3.2   (API level 13)
		4.0   (API level 14)
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.3   (API level 18)
		4.4   (API level 19)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Apple Developer Tools ===

Xcode 5.1.1 (5085)
Build 5B1008

=== Xamarin.Mac ===

Version: (Business Edition)

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: 606f31a
Build date: 2014-08-01 15:27:48-0400

=== Build Information ===

Release ID: 502010001
Git revision: d06832ce9807d6be24aca225457e8b37c7669f6f
Build date: 2014-08-07 12:10:47-04
Xamarin addins: 1de032531be4cecf2f39dbee3b87aac78204058c

=== Operating System ===

Mac OS X 10.9.3
Darwin Xamarin76s-Mac-mini.local 13.2.0 Darwin Kernel Version 13.2.0
    Thu Apr 17 23:03:13 PDT 2014
    root:xnu-2422.100.13~1/RELEASE_X86_64 x86_64
Comment 4 Jason Smith [MSFT] 2014-09-23 01:24:45 UTC
Setting AnchorX is not supposed to result in any translation to the image itself. This is a mistake that should be fixed now.
Comment 5 Brendan Zagaeski (Xamarin Team, assistant) 2014-10-17 20:39:51 UTC
Just to save anyone the time of testing, it looks like this fix hasn't yet made it into a Xamarin.Forms release.

- (Released 2014-10-02)
- (Released 2014-10-08)

Given the relatively close timing between comment 4 and these two releases, I suspect the fix simply hasn't made its way into a release branch yet. I expect the 1.3 -pre1 release will include it.
Comment 6 Brendan Zagaeski (Xamarin Team, assistant) 2014-11-05 23:35:04 UTC
Correction to my previous comment (comment 5):

The Anchor properties _do_ work in, **but** on Android the anchor positions are by default calculated before the elements have non-zero sizes, so the initial pixel positions of the anchor are always calculated to be 0. The Xamarin.Forms team is working on fixing that (other) problem.

## Possible workaround

If you wait until late enough in the display update process, the elements do eventually get non-zero sizes.

For example, one workaround is to set the Anchor positions in the `LayoutChildren()` override. If you set the anchor positions after the call to `base.LayoutChildren()`, they behave (almost) correctly. The one extra problem is that you must set the Anchor positions to values other than (0.5, 0.5). For example, you can use (0.49, 0.51). The problem with using (0.5, 0.5) is that the property setter will see that the values are unchanged from their defaults, and so will return immediately without updating the calculated pixel coordinates. If you like, you can also set the anchor to (0, 0), and then _back_ to (0.5, 0.5) to achieve the correct behavior.
Comment 7 Parmendra Kumar 2015-08-11 14:15:06 UTC
I have checked this issue with attached sample project in bug description and I am still getting same behavior mentioned in bug description with Xamarin.Forms

Screencast: http://www.screencast.com/t/pJwiCJ5iSOCD

Could you please let me know should I close this issue with provided workaround in comment #6?