【问题标题】:Disable Xamarin Form and Show Activity Indicator禁用 Xamarin 表单并显示活动指示器
【发布时间】:2016-10-14 13:25:54
【问题描述】:

我有一个使用滚动视图的 Xamarin 表单。 我试图在顶部显示一个活动指示器,因为我在中间有一个 ListView。 但是当用户向下滚动时,不会显示加载。 所以,我需要帮助来禁用页面并在某个 z-index 显示加载,就像在弹出窗口中一样。

【问题讨论】:

    标签: xamarin xamarin.forms scrollview activity-indicator


    【解决方案1】:

    如果你想在屏幕加载时有一个覆盖,你可以这样做。

    <Grid>
    
        <ScrollView>
           <!-- Insert your page content in here -->
        </ScrollView>
    
        <ContentView IsVisible="false" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
             <ActivityIndicator IsRunning="false" />
        </ContentView>
    
    </Grid>
    

    当您将 ContentView 设置为 IsVisible="true" 时,它将覆盖在您的页面顶部。如果需要,您可以在 ContentView 上设置背景颜色和不透明度以提供灰显效果。

    或者你可以使用类似的方法并拥有

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
    
        <ActivityIndicator Grid.Row="0" />
    
        <ScrollView Grid.Row="1">
    
        </ScrollView>
    </Grid>
    

    通过这种方式,您将始终在滚动视图上方显示活动指示器,并允许用户仍然滚动。

    【讨论】:

    • 感谢您的回答。会试试这个。
    • 这很好用!你能告诉我使用Grid的原因吗?
    • @Curiousity,这里使用了 Grid(在上面的例子中,ContentView 在 z 轴上覆盖了 ScrollView),因为 ScrollView 和 ContentView 都以相同大小的区域矩形占据第 0 行。 ContentView 在 z 轴上较高,但最初是不可见的,直到后来变得可见,在 ScrollView 前面黯然失色。没有其他控件可以像复制行 ID 一样轻松地使这种同时占用相同区域矩形的技巧发挥作用。
    • 感谢@optikos 的解释
    【解决方案2】:

    我是 Xamarin 的新手,但您按以下方式操作。

     <Grid IsEnabled="{Binding IsBusy,Converter={converters:InverseBoolConverter}}"   >
    ...
         <ActivityIndicator      
                  Color="{StaticResource LightGreenColor}"
                  IsRunning="{Binding IsBusy}"
                  IsVisible="{Binding IsBusy}"
                  VerticalOptions="Center"
                  HorizontalOptions="Center">
                    <ActivityIndicator.WidthRequest>
                        <OnPlatform x:TypeArguments="x:Double">
                            <On Platform="iOS, Android" Value="100" />
                            <On Platform="UWP, WinRT, WinPhone" Value="400" />
                        </OnPlatform>
                    </ActivityIndicator.WidthRequest>
                </ActivityIndicator>
            </Grid>
    

    【讨论】:

      猜你喜欢
      • 2019-02-04
      • 1970-01-01
      • 2017-12-30
      • 1970-01-01
      • 2012-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多