How can I make platform specific RelativeLayout.XConstraint in XAML?

I have an activity indicator that isn't aligning the same on iOS/Android. Here is what I currently have that does't work.

<ContentView>
    <RelativeLayout>
        <Button x:Name="LoginBtn" Text="{Extensions:TranslateExtension Text=Join}" WidthRequest="300" />
        <ActivityIndicator x:Name="actIndicator" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand">
            <ActivityIndicator.RelativeLayout.XConstraint>
                <OnPlatform x:TypeArguments="Constraint" 
                    iOS="{ConstraintExpression Type=RelativeToView, Property=Width, ElementName=LoginBtn, Factor=0.47}" 
                    Android="{ConstraintExpression Type=RelativeToView, Property=Width, ElementName=LoginBtn, Factor=0.42}" />
            </ActivityIndicator.RelativeLayout.XConstraint>
            <ActivityIndicator.RelativeLayout.YConstraint>
                <OnPlatform x:TypeArguments="Constraint" 
                    iOS="{ConstraintExpression Type=RelativeToView, Property=Height, ElementName=LoginBtn,Factor=0.28}" 
                    Android="{ConstraintExpression Type=RelativeToView, Property=Height, ElementName=LoginBtn,Factor=0.025}" />
            </ActivityIndicator.RelativeLayout.YConstraint>
        </ActivityIndicator>
    </RelativeLayout>
</ContentView>

Answers

  • leye0leye0 USMember ✭✭

    "Doesn't work" like what.

  • ToddHenderson.2793ToddHenderson.2793 USMember ✭✭
    edited December 2015

    Compiles and runs but Activity indicator is not centered. I can do something like the code below to get it centered in one platform at a time. But I can't get it to work with the on platform directive.

    <ActivityIndicator x:Name="actIndicator" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand"
        RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToView, Property=Width, ElementName=LoginBtn, Factor=0.42}"
        RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToView, Property=Height, ElementName=LoginBtn,Factor=0.025}">
    
  • SuchithSuchith INMember ✭✭✭

    @ToddHenderson.2793 this is throwing me below error : "Constraints as specified contain an unsolvable loop" .
    How to make this RelativeLayout.XConstraint and RelativeLayout.YConstraint platform specific ?

Sign In or Register to comment.