I want the image to occupy the remaining space in StackLayout, however somehow this seems impossible in XAML. The image always tries to display itself with the maximum available size.
<StackLayout>
<Image Source="{Binding ProfileImage}" Aspect="AspectFit" HorizontalOptions="Center" VerticalOptions="Start" />
<StackLayout Orientation="Vertical" HorizontalOptions="Fill" VerticalOptions="EndAndExpand">
<Button HorizontalOptions="FillAndExpand" VerticalOptions="End" x:Name="_ButtonShare" Text="Share" />
<Button HorizontalOptions="FillAndExpand" VerticalOptions="End" x:Name="_ButtonExternalLinks" Text="External links"/>
</StackLayout>
</StackLayout>
I tried different Vertical- and HorizontalOptions for this, but the second button is always squeezed out of the view. Using a certain height is also not the best solution.
It seems that this is possible with a relative layout, but that means I'm attached to relative values, which is not very good if I am targeting different devices (e.g. iPhone4S and iPhone5).
<RelativeLayout>
<Image Source="{Binding ProfileImage}" Aspect="AspectFit"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}"
RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0.7}"/>
<StackLayout Orientation="Vertical"
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0.8}"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}"
RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0.2}">
<Button HorizontalOptions="FillAndExpand" VerticalOptions="End" x:Name="_ButtonShare" Text="Share" />
<Button HorizontalOptions="FillAndExpand" VerticalOptions="End" x:Name="_ButtonExternalLinks" Text="External links"/>
</StackLayout>
</RelativeLayout>
How can I do it right?
source
share