特定于Android的动画Xamarin.Forms-启动画面 [英] Android specific animations Xamarin.Forms - Splash screen

查看:137
本文介绍了特定于Android的动画Xamarin.Forms-启动画面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have made a splash screen for Android by implementing a new Activity. It points to a xml theme that includes android specific code (@style/Splash). That points to a drawable xml of splash.

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

My question is, If we can do these kinds of platform specific implementations, can we also create animations using this same pattern? I have placed an example of code from the android dev website to give you an idea of what I am trying to include. If yes, what would this code look like in XF.Android and how can we reference it?

SplashActivity.cs

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的示例动画

Example anim that I want to include 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>

推荐答案

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

1. Create a Anim folder and put the hyperspace_jump.xml file in it.

2.创建布局.

SplashScreen布局:

SplashScreen Layout:

 <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:

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));
    }
}

MainActivity:

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

You could download from the GitHub for reference. https://github.com/WendyZang/Test/tree/master/SplashScreenDemo

这篇关于特定于Android的动画Xamarin.Forms-启动画面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆