Reputation: 2716
I am trying to show an Activity Indicator in my App for which I have written the following code but the indicator is not getting rendered on the screen. Can somebody please suggest what has gone wrong?
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;
Upvotes: 0
Views: 171
Reputation: 2761
Try this
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);
Add the indicator after the stack. absolute.Children.Add(indicator)
after absolute.Children.Add(stack)
;
Check If your IsVisible
is true.
Upvotes: 1