在 Xamarin Forms 中加载查看内容时显示活动指示器

2023-12-23

有没有办法在页面内容视图渲染或加载时显示活动指示器?我问这个是因为当我在页面中有很多控件并且我想导航到该页面时,需要几秒钟的时间到页面。所以我想知道是否有一种方法可以即时导航页面,并且当页面出现时显示加载内容的活动指示器,以及当内容加载时显示它。


有没有办法在页面内容视图渲染或加载时显示活动指示器?

  1. 我们需要在PCL中创建服务名称ILodingPageService接口。

     public interface ILodingPageService
      {
     void InitLoadingPage(ContentPage loadingIndicatorPage = null);
     void ShowLoadingPage();
     void HideLoadingPage();
    
      }
    
  2. 创建透明页面以显示活动指示器。

     <ContentPage.Content>
         <StackLayout
             Padding="30"
             BackgroundColor="Black"
             HorizontalOptions="Center"
             VerticalOptions="Center">
    
             <ActivityIndicator IsRunning="True" Color="White" />
    
             <Label
                 FontAttributes="Bold"
                 Text="Loading..."
                 TextColor="White" />
    
         </StackLayout>
     </ContentPage.Content>
    
  3. 在Android平台上实现ILodingPageService接口。

     [assembly: Xamarin.Forms.Dependency(typeof(LodingPageServiceDroid))]
     namespace IndicatorApp.Droid
     {  
         public class LodingPageServiceDroid : ILodingPageService
         {
    
             private Android.Views.View _nativeView;
             private Dialog _dialog;
             private bool _isInitialized;
             public void HideLoadingPage()
             {
                 // Hide the page
    
                 _dialog.Hide();
             }
    
             public void InitLoadingPage(ContentPage loadingIndicatorPage = null)
             {
                 // check if the page parameter is available
                 if (loadingIndicatorPage != null)
                 {
                     // build the loading page with native base
                     loadingIndicatorPage.Parent = Xamarin.Forms.Application.Current.MainPage;
                     loadingIndicatorPage.Layout(new Rectangle(0, 0,
                     Xamarin.Forms.Application.Current.MainPage.Width,
                     Xamarin.Forms.Application.Current.MainPage.Height));
                     var renderer = loadingIndicatorPage.GetOrCreateRenderer();
                     _nativeView = renderer.View;
                     _dialog = new Dialog(CrossCurrentActivity.Current.Activity);
    
                     _dialog.RequestWindowFeature((int)WindowFeatures.NoTitle);
    
                     _dialog.SetCancelable(false);
    
                     _dialog.SetContentView(_nativeView);
    
                     Window window = _dialog.Window;
    
                     window.SetLayout(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
    
                     window.ClearFlags(WindowManagerFlags.DimBehind);
    
                     window.SetBackgroundDrawable(new ColorDrawable(Android.Graphics.Color.Transparent));
                     _isInitialized = true;
                 }
             }
    
             public void ShowLoadingPage()
             {
                 // check if the user has set the page or not
                 if (!_isInitialized)
                     InitLoadingPage(new LoadingIndicatorPage1()); // set the default page
    
                 // showing the native loading page
    
                 _dialog.Show();
             }
         }
         internal static class PlatformExtension
         {
             public static IVisualElementRenderer GetOrCreateRenderer(this VisualElement bindable)
             {
                 var renderer = XFPlatform.GetRenderer(bindable);
                 if (renderer == null)
                 {
                     renderer = XFPlatform.CreateRendererWithContext(bindable, CrossCurrentActivity.Current.Activity);
    
                     XFPlatform.SetRenderer(bindable, renderer);
    
                 }
    
                 return renderer;
    
             }
    
         }
     }
    

截图在这里:

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 Xamarin Forms 中加载查看内容时显示活动指示器 的相关文章

随机推荐

  • setTimeout返回什么?

    我很好奇 setTimeout 返回什么 所以我做了一个快速测试 var thing setTimeout function 1 让我惊讶的是它给了我一个数字 1351每次都是不同的 那么它返回的真的只是一个数字吗 那么我实际上也可以这样做
  • 交叉过滤查询

    是否可以过滤以数组作为值的交叉过滤数据集 例如 假设我有以下数据集 var data bookname the joy of clojure authors Michael Fogus Chris Houser tags clojure l
  • 如果定义了属性,则从 Waterline 中的模型中获取结果

    我有一个模型 其中不需要每个属性 我想查询模型并返回属性所在的所有实例is定义的 这就是我的think代码应该看起来像这样 但它不起作用 有什么想法或一些详细文档的链接吗 MyModel find where propertyThatMay
  • iOS SDK:切换相机时如何导致视图翻转

    在 iOS Objective C 上相当新 我正在对 Apple 进行修改AVCam http bit ly IFQn3h 视频采集 示例代码 想在前后摄像头切换时模仿原生摄像头的翻转动画 看起来这似乎很容易 但我无法掌握它是如何完成的
  • extjs解析模板中嵌套的json

    尝试 未成功 显示嵌套 json 中的数据 JSON 可能看起来像 contacts id 1 client id 135468714603 addresses id 1 contact id 1 address id 16 address
  • R中magrittr和arima的兼容性问题

    考虑以下示例 library tidyverse set seed 1 forecast forecast x lt cumsum rnorm 10 y1 lt arima x order c 1 0 0 y2 lt x gt arima
  • 保存模型会破坏一对多关系

    当我保存一个父对象 其中有许多子对象 时 这种关系似乎被破坏了 这Ember 文档 http emberjs com guides models persisting records 在这个问题上保持沉默 我需要做什么才能使父对象仍然显示子
  • JavaScript 中 += 和 =+ 的区别

    我想知道为什么运行第三行代码后的结果是a is 5 a 10 b 5 a b 尴尬的格式 a b 相当于 a b And b只是一种奇特的铸造方式b编号 如下所示 var str 123 var num str 您可能想要 a b 相当于
  • Nginx server_name regexp 不能作为变量使用

    有人告诉我为什么我仍然遇到这样的错误吗 Restarting nginx emerg unknown domain name variable configuration file etc nginx nginx conf test fai
  • Dapper MultiMap 不适用于具有 NULL 值的 splitOn

    我在尝试在包含以下内容的列上进行拆分时 在 dapper 中遇到了 MultiMaps 的问题NULL Dapper 似乎没有实例化对象 我的映射函数接收到null而不是对象 这是我的新测试 class Product public int
  • 响应宽度 Facebook 页面插件

    Facebook 推出了新的页面插件来取代 Like 框插件 文档 https developers facebook com docs plugins page plugin https developers facebook com d
  • 在 Highcharts 股票图表上将最后一点的值显示为标签或工具提示

    我在一张股票图表 HighCharts 中有多个不同比例的数据系列 我想将每个系列连接到它的轴或显示每个系列的最后一个点的值 类似于数据标签 但仅适用于每个系列的最后一个点 function container highcharts cha
  • 如何在 contenteditable div 中输入时创建一个段落?

    我正在为我的一个项目制作一个简单的编辑器 我需要使用可编辑的 div 使用contenteditable财产 我需要两个功能 输入两次后自动插入小时 创建一个段落而不是 br 进入并专注于它 所以我写了这个 带着一些灵感 这是负责的代码的一
  • 如何将 EditTextPreference 限制在范围 1024:65535

    我有一个 EditTextPreference 定义为
  • missModalViewControllerAnimated 非原子的?

    看来我有一个奇怪的时间问题 我打开 uiimagepicker 作为模态视图 当用户选择图像或我想要拍摄图像时 将其保存到变量中 然后以模态视图打开电子邮件界面 我的问题是 我在图像选择器上调用dismissModalViewControl
  • Visual Studio 2017 和 SAP Crystal Reports

    我已经下载并安装了视觉工作室 2017 社区之后我下载并安装了Crystal Report 支持包 20 v 13 0 20 2399 我打开了视觉工作室2017并创建一个新项目 然后右键单击我的项目 然后单击添加项目 我寻找水晶报告 rp
  • 提升文件末尾序列化

    我使用 Boost 将多个对象序列化为二进制存档 当从 a 读回这些对象时binary iarchive 有没有办法知道存档中有多少对象 或者只是检测存档结尾的方法 我发现的唯一方法是使用 try catch 来检测流异常 提前致谢 我可以
  • ggplot:如何根据相对于绘图宽度的边距来换行标题文本

    当使用绘图时ggplot2 如何将标题文本换行以适应相对于绘图整个宽度的边距 library ggplot2 library stringr my title lt c reltively long sentences that norma
  • 在 Objective-C 框架中使用 Swift 闭包

    我正在使用 MCSwipeTableViewCell 框架来实现可滑动的 tableviewcell 内的完成块之一cellForRowAtIndexPath函数看起来像这样 cell setSwipeGestureWithView che
  • 在 Xamarin Forms 中加载查看内容时显示活动指示器

    有没有办法在页面内容视图渲染或加载时显示活动指示器 我问这个是因为当我在页面中有很多控件并且我想导航到该页面时 需要几秒钟的时间到页面 所以我想知道是否有一种方法可以即时导航页面 并且当页面出现时显示加载内容的活动指示器 以及当内容加载时显