Xamarin儿童添加了多个AbsoluteLayoutFlags

问题描述 投票:1回答:1

如果有可能为孩子添加多个AbsoluteLayoutFlags,我会徘徊吗?什么时候在c#中做?

我知道在XAML中有可能:

StackLayout BackgroundColor="White"
            Orientation="Horizontal" 
            HorizontalOptions="FillAndExpand"
            AbsoluteLayout.LayoutBounds="0, 0, 1, 90"
            AbsoluteLayout.LayoutFlags="PositionProportional, WidthProportional">

但是当我尝试用c#做这个时,我显然只能添加一个:

layout.Children.Add(topMenu(), new Rectangle(0, 0, 1, 90), AbsoluteLayoutFlags.PositionProportional);

希望得到这方面的帮助,并提前感谢:-)

c# xamarin position
1个回答
1
投票

只需在Flags之间添加OR运算符即可

layout.Children.Add(topMenu, new Rectangle(0, 0, 1, 90), AbsoluteLayoutFlags.PositionProportional|AbsoluteLayoutFlags.SizeProportional|AbsoluteLayoutFlags.SizeProportional);

您可以附加|运算符如何为AbsoluteLayoutFlags enum提供任何值。或者你可以尝试下面一个

您可以将AbsoluteLayoutFlags单独添加到任何控件中。看看这个示例代码片段

var layout = new AbsoluteLayout
{    
    BackgroundColor = Color.Blue.WithLuminosity(0.9),
    VerticalOptions = LayoutOptions.FillAndExpand
};    

var topMenu = new Label
{
    Text = "Left",
    TextColor = Color.Black
};

AbsoluteLayout.SetLayoutFlags(topMenu,
AbsoluteLayoutFlags.None|AbsoluteLayoutFlags.PositionProportional);

AbsoluteLayout.SetLayoutBounds(topMenu,
new Rectangle(0, 0, 1, 90));

layout.Children.Add(topMenu); 
© www.soinside.com 2019 - 2024. All rights reserved.