无法正确添加活动指标

时间:2018-04-02 17:09:36

标签: xamarin

我的CreateRegisterView函数返回我期望的结果

我的功能的最后一行

var content = new StackLayout 
{ 
    Margin = 0, 
    Padding = 0, 
    BackgroundColor = Color.Gold 
};
content.Children.Add(forms);
content.Children.Add(new BoxView 
{ 
    Margin = 0, 
    Color = Color.Red, 
    VerticalOptions = LayoutOptions.FillAndExpand 
});

AbsoluteLayout.SetLayoutFlags(content, AbsoluteLayoutFlags.PositionProportional);
AbsoluteLayout.SetLayoutBounds(content, new Rectangle(0f, 0f, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
AbsoluteLayout.SetLayoutFlags(_ActivityIndicator, AbsoluteLayoutFlags.PositionProportional);
AbsoluteLayout.SetLayoutBounds(_ActivityIndicator, new Rectangle(0.5, 0.5, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));

var overlay = new AbsoluteLayout();

overlay.Children.Add(content);
overlay.Children.Add(_ActivityIndicator);

return overlay;

enter image description here

但是只要我添加活动指标,我就会得到这个结果 enter image description here

1 个答案:

答案 0 :(得分:0)

我没有看到_ActivityIndicator的任何定义。对于您所面临的问题,唯一的解释是_ActivityIndicator在某些代码中引用了content的相同实例。

如果不是这样,请尝试更改您的界限,摆脱AutoSizecontent视图。

像这样:

AbsoluteLayout.SetLayoutBounds(content, new Rectangle(0f, 0f, 1f, 1f));
AbsoluteLayout.SetLayoutFlags(content, AbsoluteLayoutFlags.All);
AbsoluteLayout.SetLayoutBounds(_ActivityIndicator, new Rectangle(0.5, 0.5, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
AbsoluteLayout.SetLayoutFlags(_ActivityIndicator, AbsoluteLayoutFlags.PositionProportional);