c# - 在 Xamarin.Forms 上将 Activityindicator 居中

标签 c# xaml xamarin xamarin.forms

我有上面的 XAML 代码,我试图在单击按钮后将 ActivityIndi​​cator 放在页面的中央。我尝试使用网络示例,但没有成功。

<ScrollView>
  <StackLayout>
    <StackLayout Padding="30" Spacing="2" VerticalOptions="CenterAndExpand" HorizontalOptions="FillAndExpand">
      <Label x:Name="lblUsuario" Text="ID do Usuário" TextColor="#555" FontSize="20" FontAttributes="Bold"/>
      <Entry x:Name="EntUsuario" Keyboard="Numeric" Placeholder="Digite usuário" PlaceholderColor="#CCC" FontSize="20" TextColor="#555" />
      <Label x:Name="lblSenha" Text="Senha de acesso" TextColor="#555" FontSize="20" FontAttributes="Bold"/>
      <Entry x:Name="EntSenha" Placeholder="Digite sua senha" Keyboard="Default" IsPassword="True" FontSize="20" PlaceholderColor="#CCC" TextColor="#555" />   
    </StackLayout>
    <StackLayout Padding="30" VerticalOptions="CenterAndExpand" HorizontalOptions="FillAndExpand">  
      <Button x:Name="BtnLogin" Text="Login" BorderColor="#CB9600" BackgroundColor="#F4B400" />
    </StackLayout> 
  </StackLayout>
</ScrollView>

这是代码的开头:

public partial class LoginPage : ContentPage
    {
        public LoginPage()
        {
            IsBusy = false;
            InitializeComponent();

            int contadorErroLogin = 0;
            string result = null;

            BtnLogin.Clicked += async (sender, e) =>
                {
                    IsBusy = true;

当开始时 IsBusy = false 但屏幕看起来像是 true 。

最佳答案

尝试使用这个:

<AbsoluteLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">

       <StackLayout AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1">
           <ScrollView>
              <StackLayout>
                  <StackLayout Padding="30" Spacing="2" VerticalOptions="CenterAndExpand" HorizontalOptions="FillAndExpand">
                    <Label x:Name="lblUsuario" Text="ID do Usuário" TextColor="#555" FontSize="20" FontAttributes="Bold"/>
                    <Entry x:Name="EntUsuario" Keyboard="Numeric" Placeholder="Digite usuário" PlaceholderColor="#CCC" FontSize="20" TextColor="#555" />
                    <Label x:Name="lblSenha" Text="Senha de acesso" TextColor="#555" FontSize="20" FontAttributes="Bold"/>
                    <Entry x:Name="EntSenha" Placeholder="Digite sua senha" Keyboard="Default" IsPassword="True" FontSize="20" PlaceholderColor="#CCC" TextColor="#555" />   
               </StackLayout>
               <StackLayout Padding="30" VerticalOptions="CenterAndExpand" HorizontalOptions="FillAndExpand">  
                    <Button x:Name="BtnLogin" Text="Login" BorderColor="#CB9600" BackgroundColor="#F4B400" />
               </StackLayout> 
             </StackLayout>
            </ScrollView>

        </StackLayout>

       <StackLayout IsVisible="{Binding IsBusy}" Padding="12"
                 AbsoluteLayout.LayoutFlags="PositionProportional"
                 AbsoluteLayout.LayoutBounds="0.5,0.5,-1,-1">

       <ActivityIndicator IsRunning="{Binding IsBusy}" Color ="#80000000"/>

       <Label Text="Loading..." HorizontalOptions="Center" TextColor="White"/>

        </StackLayout>

 </AbsoluteLayout>

关于c# - 在 Xamarin.Forms 上将 Activityindicator 居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40027196/

相关文章:

c# - 过滤一组包含其他短语的所有短语的算法

c# - 访问 TreeView 中的父节点?

image - 在按钮中居中图标和文本 Xamarin XAML

c# - 使用一个 DependencyProperty 在 UserControl 中绑定(bind)具有多个属性的模型

c# - 如何使用 iOS 相机拍照并使用 Xamarin 将图像保存到相机胶卷

c# - 如果另一个线程已获取关键部分的锁,如何停止线程?

c# - ReSharper 使用 SqlDataReader 显示警告

c# - 使用 MVVM Xamarin Forms 使用数据填充选择器

c# - 启动 Windows 服务时找不到 app.config

c# - 使用 Place API 在 xamarin android 中填充附近地点的 map