活动指示器未显示在middile中 - XamarinForms WinPhone81

时间:2017-01-31 05:05:39

标签: c# xamarin.forms

我在XamarinForms项目中遇到了ActivityIndi​​cator的奇怪行为。该指标在WinPhone81中完美加载,但第一次没有在布局的中间加载,但它从第二次到无限运行完美。以下是我使用的代码:

在XAML中:

<StackLayout x:Name="blueBar" Padding ="0,0,0,0" Orientation ="Vertical"
HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" >
</StackLayout>

在CS中:

ActivityIndicator loading = new ActivityIndicator();

    blueBar.Children.Add(loading);
    loading.IsRunning = true;
    //some functions
    blueBar.Children.Remove(loading);

有没有人知道它为什么会这样??

任何建议/指南/帮助将不胜感激.. !!

提前致谢。

Note: The ActivityIndicator works well and fine in Droid & iOS projects.

输出:我正在体验

1.首次执行页面:

enter image description here

2.同一页面的第二次执行:

enter image description here

输出:根据-Chandresh Khambhayata

enter image description here

3 个答案:

答案 0 :(得分:0)

您似乎需要先将StackLayout放在AbsoluteLayout内,以便将ActivityIndicator调整到中间位置。

这应该install curl and Git with openssl帮助你。

还没有尝试过,但看起来你需要做很多事情来实现它。

希望它有所帮助!

答案 1 :(得分:0)

如果您想在屏幕中央显示ActivityIndi​​cator,那么您最需要应用HorizontalOptions="Center"VerticalOptions="Center"

我正在使用以下XML代码,它对我来说非常适合。

<StackLayout VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand">
    <ActivityIndicator Color="White" HorizontalOptions="Center"  VerticalOptions="Center" />
    <Label Grid.Row="1" x:Name="LabelLoading" HorizontalOptions="Center" TextColor="White" Text="Loading..." FontFamily="Droid Sans Mono" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" />
</StackLayout>

以编程方式设置活动指标。

ActivityIndicator activityIndecator = new ActivityIndicator();
activityIndecator.Color = Color.White;
activityIndecator.HorizontalOptions = LayoutOptions.Center;
activityIndecator.VerticalOptions = LayoutOptions.Center;
blueBar.Children.Remove(activityIndecator);

谢谢。

答案 2 :(得分:0)

感谢您帮助我们......

我终于找到了我的问题的答案......

以下是我的工作代码(在所有三个平台上)。

XAML:

<StackLayout x:Name="blueBar" Padding="0,0,0,0" Orientation="Vertical" VerticalOptions="FillAndExpand" >
   <ActivityIndicator x:Name="loading" IsRunning="true"></ActivityIndicator>
</StackLayout>

CS:

somebtn.Clicked += async(sender,e) => {

    loading.IsVisible = true;

    //some await functions like api call or something

    loading.IsVisible = false;
}

实际问题是。,之前的InitializeComponent()没有分配指标。所以当我第一次点击任何一个按钮时,指示符显示在布局的左边。

但是,现在指标由InitializeComponent()初始化,因此指标显示在第一次点击的中间......

Note : This problem only occured on windowsphone only not on ios and android projects.
       Now the updated code works well and good on all the three platforms.
相关问题