【问题标题】:Animation when downloading the program下载程序时的动画
【发布时间】:2019-05-02 12:53:19
【问题描述】:

在这里我无法弄清楚动画。加载程序时需要实现动画,以及单个屏幕状态的动画转换,我该如何实现这个帮助? enter image description here

【问题讨论】:

    标签: c# android visual-studio xamarin xamarin.forms


    【解决方案1】:

    这是一个简单的加载动画。是不是你需要的:

    自定义一个ShowLoading.cs界面:

    public interface ShowLoading
    {
        void Show();
        void Hide();
    }
    

    然后在.Android MainActivity.cs中实现接口:

    [assembly: Dependency(typeof(MainActivity))]
    namespace App18.Droid
    {
    [Activity(Label = "App18", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity,ShowLoading
    {
        private  static Dialog _dialog;
        public void Hide()
        {
            _dialog.Dismiss();
    
        }
    
        public void Show()
        {
            _dialog.Show();
        }
    
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;
    
            base.OnCreate(savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
            LoadApplication(new App());
            init();
        }
    
        private void init()
        {
            View view = LayoutInflater.From(this).Inflate(Resource.Layout.loading_layout,null);
            _dialog = new Dialog(this);
            _dialog.RequestWindowFeature((int)WindowFeatures.NoTitle);
            _dialog.SetCancelable(false);
            _dialog.SetContentView(view);
        }
    }
    

    }

    loading_layout.axml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:id="@+id/frame"
     >
    
      <ProgressBar
        android:id="@+id/loading"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_centerInParent = "true"
        android:indeterminateBehavior="repeat"
        android:indeterminateDrawable="@drawable/loading" />
    </RelativeLayout>
    

    loading.xml(在 Resources/drawable 中):

    <?xml version="1.0" encoding="utf-8"?>
    <animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
                 android:drawable="@drawable/loadingicon"
                 android:fromDegrees="0.0"
                 android:pivotX="50.0%"
                 android:pivotY="50.0%"
                 android:toDegrees="360.0" />
    

    您可以在您的页面中通过 DependencyService 调用它,如下所示:

    //show the loadig animation
    DependencyService.Get<ShowLoading>().Show();
    
    //hide it
    DependencyService.Get<ShowLoading>().Hide();
    

    【讨论】:

    • 需要在 Xamarin 上实现,而不是在 Java 上实现
    • 我已经更新了 Xamarin.Forms 中的答案,您可以通过 DependencyService 实现它
    【解决方案2】:

    如果您使用 Xamarin,请查看 SkiaSharp。您可以非常轻松地创建矢量图形并为其设置动画。

    【讨论】:

    猜你喜欢
    • 2013-03-20
    • 2019-02-15
    • 2018-03-31
    • 1970-01-01
    • 2014-09-30
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 2020-02-13
    相关资源
    最近更新 更多