Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Android Anchors

$
0
0

AnchorX and AnchorY are not working in Andriod when used within an relative layout.

I am using AnchorX to change an objects anchor point to its upper right corner for translations so I can right align elements. This works fine in iOS but not in Andriod. I have tried generating my views using both C# and XAML, both have the same issue. This bug has persisted since the first public release.

Any help would be appreciated as xamarin support was not able to give me a work around and I have a deadline coming up with Droid views that are show stoppers.

Simple Example Case:

public class TestView : ContentPage
{

    public TestView()
    {
        var layout = new RelativeLayout();

        Label l = new Label
        {
            Text = "Test Label",
            AnchorX = 0,
            AnchorY = 0,
            BackgroundColor = Color.Red
        };

        layout.Children.Add(l, Constraint.RelativeToParent((parent) => { return parent.Width / 2; }), Constraint.RelativeToParent((parent) => { return parent.Height / 2; }));

        Content = layout;
    }

}

If you play around with the anchor points it will not change on driod, leaving the label slightly bottom-right of center (anchored top left). Setting the anchors to (0,0) will center the label on screen in iOS as it should.


Viewing all articles
Browse latest Browse all 58056

Trending Articles