活动指示器未在绝对布局中呈现

时间:2016-05-18 05:27:55

标签: xamarin xamarin.forms

我正在尝试在我的应用程序中显示一个活动指示器,我已经编写了以下代码,但指示器未在屏幕上呈现。 有人可以建议出了什么问题吗?

private ActivityIndicator indicator = new ActivityIndicator
{
    HorizontalOptions = LayoutOptions.CenterAndExpand,
    Color = Color.Black,

    IsVisible = false
};



StackLayout stack = new StackLayout
                {
                    VerticalOptions=LayoutOptions.FillAndExpand,
                    HorizontalOptions=LayoutOptions.FillAndExpand,
                    Padding=0,
                    Spacing=0,
                };

                AbsoluteLayout absolute = new AbsoluteLayout
                {
                    VerticalOptions = LayoutOptions.FillAndExpand,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                };


  stack.Children.Add(map);
  stack.Children.Add(browser);

AbsoluteLayout.SetLayoutFlags(stack, AbsoluteLayoutFlags.PositionProportional);
AbsoluteLayout.SetLayoutBounds(stack, new Rectangle(0f, 0f, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));

AbsoluteLayout.SetLayoutFlags(indicator, AbsoluteLayoutFlags.PositionProportional);
AbsoluteLayout.SetLayoutBounds(indicator, new Rectangle(0.5f, 0.5f, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));


  absolute.Children.Add(indicator);
  absolute.Children.Add(stack);



*//When Some activity occurs.....Indicator is shown like this*

 indicator.SetBinding(ActivityIndicator.IsVisibleProperty, "IsBusy", BindingMode.OneWay);
            indicator.SetBinding(ActivityIndicator.IsRunningProperty, "IsBusy", BindingMode.OneWay);
            indicator.IsRunning = true;
            indicator.IsVisible = true;

1 个答案:

答案 0 :(得分:1)

试试这个

AbsoluteLayout.SetLayoutBounds(stack, new Rectangle(0f, 0f, 1f, 1f));
AbsoluteLayout.SetLayoutBounds(indicator, new Rectangle(0.5f, 0.5f, -1f, -1f));
AbsoluteLayout.SetLayoutFlags(stack, AbsoluteLayoutFlags.All);

在堆栈后添加指标。 absolute.Children.Add(indicator)后的absolute.Children.Add(stack);

检查IsVisible是否属实。