2015-06-27 2 views
2

Внутри RelativeLayout Я хочу показать некоторые элементы наверху в StackLayout, а некоторые в нижней части экрана в другой StackLayout. (Я использую относительный, потому что у меня также есть изображение, которое будет перекрывать часть вершины). Как установить нижние ограничения StackLayout в отношении нижней части родительского макета?Выровнять стек до нижней части RelativeLayout?

Это то, что я пытался, но он не работает:

<RelativeLayout x:Name="Login" BackgroundColor="#f6f6f6"> 
    <StackLayout Orientation="Vertical" HorizontalOptions="FillAndExpand" BackgroundColor="White" 
     RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}" 
     RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Y, Constant=0}" 
    > 

     <Image Source="ACSBanner.png" VerticalOptions="Center" HorizontalOptions="Center" /> 
    </StackLayout> 

    <StackLayout Orientation="Vertical" HorizontalOptions="FillAndExpand" VerticalOptions="EndAndExpand"> 
     <Label Text="Sample Text For Bottom" FontSize="Large" TextColor="Black" FontAttributes="Bold"/> 
    </StackLayout> 

</RelativeLayout> 

ответ

0

Что вам нужно сделать, это что-то вроде следующим образом (я использование кода позади себя, но картина по-прежнему будет применяться):

// Create your layouts 
var layout = new RelativeLayout(); 
var topStack = new StackLayout(); 
var bottomStack = new StackLayout(); 

// Define your views 
var image = new Image 
{ 
    Source = "ACSBanner.png" 
}; 

var label = new Label 
{ 
    Text = "Sample text for bottm" 
}; 

// Add the View(s) to your StackLayout(s) 
topStack.Children.Add(image); 
bottomStack.Children.Add(label); 

// Add your top stack to the top of the view 
layout.Children.Add(topStack, 
widthConstraint: Constraint.RelativeToParent(parent => 
{ 
    return parent.Width; 
}), 
yConstraint: Constraint.RelativeToParent(parent => 
{ 
    return parent.Y; 
})); 

// Add your bottom stack to the bottom of the view 
layout.Children.Add(bottomStack, 
widthConstraint: Constraint.RelativeToParent(parent => 
{ 
    return parent.Width; 
}), 
yConstraint: Constraint.RelativeToParent(parent => 
{ 
    // Find the view of the parent and substracting the height of the View which is to be positioned in the bottom 

    return parent.Height - bottomStack.Height; 
})); 

Content = relativeLayout; 
Смежные вопросы