首页 > 解决方案 > 在 xamarin 形式的初始屏幕中动画或从底部到顶部的过渡?

问题描述

我试图在初始屏幕的底部有一个带有徽标的背景图像。一旦在 ios 和 Android(xamarin 表单)中加载初始屏幕,就会发生从底部到中心的转换。请分享你的想法?

标签: androidiosxamarinxamarin.formsxamarin-studio

解决方案


如果要动画启动画面,请按照以下步骤操作。我在 Android 中做了一个示例。

首先,请创建 SplashScreen.axml。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
 <ImageView
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" 
    android:id="@+id/imageView1" 
    android:src="@drawable/splash_logo" 
    android:gravity="bottom|center_horizontal"/>
</LinearLayout>

其次,在Resource文件夹下创建Anim文件夹,创建bottomtotop.xml关于翻译的动画。

<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:interpolator="@android:anim/linear_interpolator">

 <translate 
         android:fromYDelta="100%p"
         android:toYDelta="0"
         android:duration="600"/>

 </set>

第三,使用动画创建新的活动名称 SplashScreenDemo.cs。设置 MainLauncher = true。

 [Activity(Label = "SplashScreenDemo", MainLauncher = true)]
public class SplashScreenDemo : Activity
{
    ImageView imageView;
    Animation view_animation;
    TextView textview;
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

        SetContentView(Resource.Layout.SplashScreen);
        imageView = FindViewById<ImageView>(Resource.Id.imageView1);
        view_animation = AnimationUtils.LoadAnimation(this, Resource.Animation.bottomtotop);
        imageView.StartAnimation(view_animation);
        view_animation.AnimationEnd += Rotate_AnimationEnd;
        // Create your application here
    }

    private void Rotate_AnimationEnd(object sender, Animation.AnimationEndEventArgs e)
    {
       // Finish();
        Intent intent;
        intent = new Intent(Application.Context, typeof(MainActivity));
        StartActivity(intent);
       
    }
}

推荐阅读