【问题标题】:Using animated Gif in Acr.UserDialog in Xamarin Forms在 Xamarin Forms 的 Acr.UserDialog 中使用动画 Gif
【发布时间】:2017-03-30 16:30:58
【问题描述】:

我正在使用 Acr.UserDialog 包将加载“屏幕”添加到我正在使用 Xamarin Forms 开发的应用程序中。我以某种方式使用它:

var loading = UserDialogs.Instance.Loading("Carregando", null, null, true, MaskType.Gradient);

loading.Show();
(...)
loading.Hide();

它工作正常。但是,我需要在这个加载“屏幕”中添加一个动画 Gif。有可能这样做吗?如果是这样,我该怎么做? Android 和 IO 的流程是一样的吗?

提前谢谢你!

【问题讨论】:

    标签: c# mobile xamarin loading gif


    【解决方案1】:

    尝试使用 WebView 来获得效果。它适用于所有平台。 您首先需要为动画编写一个 Xml 文件。 这是我的 XML 文件示例:

       <?xml version="1.0" encoding="utf-8"?>
       <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:orientation="vertical"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             >
    
       <WebView
             android:id="@+id/webLoadingIcon"
             android:layout_width="44dp"
             android:layout_height="44dp"
             android:layout_gravity="center_horizontal|center_vertical"
             android:layout_marginTop="120dp"
             android:background="#00000000"
             />
    
       </LinearLayout>
    

    “webLoadingIcon”代表您要使用的 .gif 照片的名称。 然后创建一个在屏幕上使用和加载 .gif 照片的方法。 这是一个示例:

       void LoadAnimatedGif()
       {
            webLoadingIcon = currentView.FindViewById<WebView>(Resource.Id.webLoadingIcon);
            // expects to find the 'loading_icon_small.gif' file in the 'root' of the assets folder, compiled as AndroidAsset.
            webLoadingIcon.LoadUrl(string.Format("file:///android_asset/loading_icon_small.gif"));
            // this makes it transparent so you can load it over a background
            webLoadingIcon.SetBackgroundColor(new Color(0,0,0,0));
            webLoadingIcon.SetLayerType(LayerType.Software, null);
       }
    

    希望对你有所帮助! :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-24
      • 1970-01-01
      • 1970-01-01
      • 2017-05-23
      • 1970-01-01
      • 2018-12-26
      • 2020-03-16
      • 2019-12-14
      相关资源
      最近更新 更多