Xamarin Header不会结束

时间:2019-11-19 00:18:33

标签: xamarin xamarin.forms xamarin.android xamarin.ios

我有问题。我创建了此标头,但现在却在努力工作。在标题中,我想在左侧添加徽标,在其旁边添加标题图像,在右侧添加一个图像。但是,当我想在右侧添加图片时,它只会放在标题图片旁边。这是代码:

<StackLayout VerticalOptions="Fill" BackgroundColor="#212121" HeightRequest="50" HorizontalOptions="Fill" Orientation="Horizontal">
    <Image HorizontalOptions="Start" VerticalOptions="Center" Margin="5,0,0,0" Source="Logo.png" HeightRequest="30" />
    <Image HorizontalOptions="Start" VerticalOptions="Center" Source="Title_Dark.png" HeightRequest="30" />
    <Image HorizontalOptions="End" VerticalOptions="Center" Source="Nav_Menu_Dark.png" HeightRequest="30" />
</StackLayout>

我使用了HorizontalOptions="End"行,但这似乎没用!

我在做什么错了?

2 个答案:

答案 0 :(得分:0)

为外部堆栈布局设置Horizo​​ntalOptions =“ FillAndExpand”,然后将Horizo​​ntalOptions =“ EndAndExpand”设置为第三个图像。试试这个:

<StackLayout VerticalOptions="Fill" BackgroundColor="#212121" HeightRequest="50" HorizontalOptions="FillAndExpand" Orientation="Horizontal">
<Image HorizontalOptions="Start" VerticalOptions="Center" Margin="5,0,0,0" Source="Logo.png" HeightRequest="30" />
<Image HorizontalOptions="Start" VerticalOptions="Center" Source="Title_Dark.png" HeightRequest="30" />
<Image HorizontalOptions="EndAndExpand" VerticalOptions="Center" Source="Nav_Menu_Dark.png" HeightRequest="30" />

答案 1 :(得分:0)

您可以使用网格,此代码可以正常工作,但是如果您想提高响应速度,则应添加一些列定义。

<Grid BackgroundColor="#212121" HeightRequest="50">
    <Image HorizontalOptions="Start" VerticalOptions="Center" Margin="5,0,0,0" Source="Logo.png" HeightRequest="30" />
    <Image HorizontalOptions="Center" VerticalOptions="Center" Source="Title_Dark.png" HeightRequest="30" />
    <Image HorizontalOptions="End" VerticalOptions="Center" Source="Nav_Menu_Dark.png" HeightRequest="30" />
</Grid>