【问题标题】:Animate or do a transition from bottom to top in splash screen in xamarin forms?在 xamarin 形式的初始屏幕中动画或从底部到顶部的过渡?
【发布时间】:2020-12-13 05:35:19
【问题描述】:

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

【问题讨论】:

    标签: android ios xamarin xamarin.forms xamarin-studio


    【解决方案1】:

    如果你想动画启动画面,请按照以下步骤。我在 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);
           
        }
    }
    

    【讨论】:

    • 这是在 android studio 中...我正在询问 android 和 iOS 的 xamarin 表单
    • @faizal 是的,如果你想使用splashscreen,你只需在不同的平台(Android和ios)下进行。关于ios中的动画,请看:Core Animation in Xamarin.iOS
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-09
    • 2017-12-28
    • 2016-12-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-21
    相关资源
    最近更新 更多