【问题标题】:Android specific animations Xamarin.Forms - Splash screenAndroid 特定动画 Xamarin.Forms - 启动画面
【发布时间】:2020-12-14 10:01:04
【问题描述】:

我通过实现一个新的 Activity 为 Android 制作了一个启动画面。它指向一个包含 android 特定代码 (@style/Splash) 的 xml 主题。这指向一个可绘制的启动 xml。

我的问题是,如果我们可以做这些特定于平台的实现,我们是否也可以使用相同的模式创建动画?我已经放置了一个来自 android dev 网站的代码示例,让您了解我想要包含的内容。如果是,这段代码在 XF.Android 中会是什么样子?我们如何引用它?

SplashActivity.cs

    [Activity(Label = "SplashActivity", Theme = "@style/Splash", MainLauncher = true, NoHistory = true)]
    public class SplashActivity : Activity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            StartActivity(typeof(MainActivity));
        }
    }

风格/飞溅

  <style name="Splash" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowBackground">@drawable/splash</item>
  </style>

可绘制/飞溅

<?xml version="1.0" encoding="utf-8" ?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item>
    <color android:color="#03045E"/>
  </item>
  <item>
    <bitmap
      android:src="@drawable/logo1"
      android:tileMode="disabled"
      android:gravity="center"/>
  </item>
</layer-list>

我想要包含 hyperspace_jump.xml 的示例动画

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false">
    <scale
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:fromXScale="1.0"
        android:toXScale="1.4"
        android:fromYScale="1.0"
        android:toYScale="0.6"
        android:pivotX="50%"
        android:pivotY="50%"
        android:fillAfter="false"
        android:duration="700" />
    <set
        android:interpolator="@android:anim/accelerate_interpolator"
        android:startOffset="700">
        <scale
            android:fromXScale="1.4"
            android:toXScale="0.0"
            android:fromYScale="0.6"
            android:toYScale="0.0"
            android:pivotX="50%"
            android:pivotY="50%"
            android:duration="400" />
        <rotate
            android:fromDegrees="0"
            android:toDegrees="-45"
            android:toYScale="0.0"
            android:pivotX="50%"
            android:pivotY="50%"
            android:duration="400" />
    </set>
</set>

【问题讨论】:

    标签: android xml animation xamarin.forms


    【解决方案1】:

    1.创建一个Anim 文件夹并将hyperspace_jump.xml 文件放入其中。

    2。创建布局。

    启动画面布局:

     <RelativeLayout xmlns:p1="http://schemas.android.com/apk/res/android"
    p1:minWidth="25px"
    p1:minHeight="25px"
    p1:layout_width="match_parent"
    p1:layout_height="match_parent"
    p1:background="@android:color/white"
    p1:id="@+id/relativeLayout1">
    
    <ImageView
        p1:layout_width="wrap_content"
        p1:layout_height="wrap_content"
        p1:id="@+id/imageView"
        p1:layout_centerVertical="true"
        p1:layout_centerHorizontal="true"
        p1:src="@drawable/a01" />
    </RelativeLayout> 
    

    主布局:

    <?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"
    android:minWidth="25px"
    android:minHeight="25px">
    <TextView
        android:text="Main Activity Started"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textView1"/>
    </LinearLayout>
    

    3.代码背后:

    SplashScreenActivity:

    public class SplashScreenActivity : Activity
    {
        ImageView imageView;
        Animation view_animation;
        TextView textview;
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            RequestWindowFeature(Android.Views.WindowFeatures.NoTitle);
            SetContentView (Resource.Layout.SplashScreen);
            imageView = (ImageView)FindViewById(Resource.Id.imageView);
            
            view_animation = AnimationUtils.LoadAnimation(this,Resource.Animation.hyperspace_jump);
             
            imageView.StartAnimation(view_animation);
            view_animation.AnimationEnd += Rotate_AnimationEnd;
            
        }
    
        private void Rotate_AnimationEnd(object sender, Animation.AnimationEndEventArgs e)
        {
            Finish();
            StartActivity(typeof(MainActivity));
        }
    }
    

    主活动:

      protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Main);
            Toast.MakeText(this, "Welcome to MainActivity", ToastLength.Long).Show();
        }
    

    4.截图:

    您可以从 GitHub 下载以供参考。 https://github.com/WendyZang/Test/tree/master/SplashScreenDemo

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-21
      相关资源
      最近更新 更多