Search code examples
c#androidvisual-studioxamarinviewflipper

Using viewFlipper in xamarin android c#


I try to animate my 3 picture into imageview using viewflipper. I mean to make a slider image. But i'm getting error. It said "cannot convert from "Android.views.animations.animation to int.

This is image of error:

Picture of error.

Here is my codes in MainActivity.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Android.App;
    using Android.Content;
    using Android.OS;
    using Android.Runtime;
    using Android.Util;
    using Android.Views;
    using Android.Widget;
    using Android.Support.Design.Widget;
    using Android.Support.V7.App;
    using Android.Support.V4.Widget;
    using Android.Support.V4.App;
    using System.Data;
    using SupportToolbar = Android.Support.V7.Widget.Toolbar;
    using Android.Views.Animations;

    namespace image_slider
    {
        [Activity(Label = "image_slider", MainLauncher = true, Theme = "@style/Theme.DesignDemo")]
        public class MainActivity : AppCompatActivity
        {
            private SupportToolbar mToolbar;
            Animation fadeIn, fadeOut;
            ViewFlipper viewflipper;


            protected override void OnCreate(Bundle savedInstanceState)
            {
                base.OnCreate(savedInstanceState);

                // Set our view from the "main" layout resource
                SetContentView(Resource.Layout.Main);

                mToolbar = FindViewById<SupportToolbar>(Resource.Id.toolbar);
                SetSupportActionBar(mToolbar);

                viewflipper = FindViewById<ViewFlipper>(Resource.Id.viewFlipper);
                fadeIn = AnimationUtils.LoadAnimation(this, Resource.Animation.fade_in);
                fadeOut = AnimationUtils.LoadAnimation(this, Resource.Animation.fade_out);


                viewflipper.SetInAnimation(this, fade_in);
                viewflipper.SetOutAnimation(this, fade_out);
                viewflipper.SetFlipInterval(5000);
                viewflipper.StartFlipping();

            }
        }
    }

Solution

  • Try to pass just the resource like:

    fadeIn = AnimationUtils.LoadAnimation(this, Resource.Animation.fade_in);
    fadeOut = AnimationUtils.LoadAnimation(this, Resource.Animation.fade_out);
    

    Link to an example I found: https://forums.xamarin.com/discussion/38188/how-to-create-a-viewflipper-in-xamarin