意见ViewFlipper之间的幻灯片动画 [英] Slide animation between views of a ViewFlipper

查看:344
本文介绍了意见ViewFlipper之间的幻灯片动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个活动我有以下几点:

  VAR鳍= FindViewById< ViewFlipper>(Resource.Id.flipper);
flipper.Touch + = flipper_Touch;

基本实现触摸处理程序是这样的:

 浮动oldTouchValue = 0;无效flipper_Touch(对象发件人,View.TouchEventArgs E)
{
    VAR鳍=发件人为ViewFlipper;
    开关(e.Event.Action)
    {
        案例MotionEventActions.Down:
            oldTouchValue = e.Event.GetX();
            打破;        案例MotionEventActions.Up:
            浮currentX = e.Event.GetX();
            如果(oldTouchValue< currentX)
            {
                flipper.ShowNext();
            }
            否则,如果(oldTouchValue> currentX)
            {
                flipper.Show previous();
            }
            打破;
    }
}

这可以让我在不同的视图之间进行导航,但我想,使其滑动左/右

我已经看到了一些Java示例如何使它工作,但不是直接的方式把它翻译成C#。

什么是需要作出的意见滑动,有没有办法来定义动画 XML
我能够使活动的幻灯片和退出使用动画 XML ,并呼吁 OverridePendingTransition ,但我不知道如何在这里应用这些知识。


解决方案

  

这可以让我在不同的视图之间进行导航,但我想
  使其滑动左/右


ViewFlipper 已通过其 ViewAnimator 类,某些方法来设置动画的进出动作,<一个href=\"http://developer.android.com/reference/android/widget/ViewAnimator.html#setInAnimation%28android.content.Context,%20int%29\"><$c$c>setInAnimation() setOutAnimation()。这是在Android SDK,但应该有MonoDroid的对应(有不幸的是我不熟悉,所以我可能是错的)。为了有所需的动画简单地用上述两种方法来设置所需的动画(无论是XML文件或编程建动画),然后调用 showNext / previous 像你目前的方法做。

你甚至可以在Android SDK中的一些幻灯片动画,但同样,我不知道,如果他们在MonoDroid的present。

更新:这些方法的确可以在MonoDroid的和暴露的是这样的:

  //使用的内置动画之一:
flipper.SetInAnimation(这一点,Android.Resource.Animation.SlideInLeft);
flipper.SetOutAnimation(这一点,Android.Resource.Animation.SlideOutRight);//通过XML定义的自定义动画
flipper.SetInAnimation(这一点,Resource.Animation.slide_in_right);
flipper.SetOutAnimation(这一点,Resource.Animation.slide_out_left);

In an Activity I have the following:

var flipper = FindViewById<ViewFlipper>(Resource.Id.flipper);
flipper.Touch += flipper_Touch;

The basic implementation of the touch handler looks like this:

float oldTouchValue = 0;

void flipper_Touch(object sender, View.TouchEventArgs e)
{
    var flipper = sender as ViewFlipper;
    switch(e.Event.Action)
    {
        case MotionEventActions.Down:
            oldTouchValue = e.Event.GetX();
            break;

        case MotionEventActions.Up:
            float currentX = e.Event.GetX();
            if (oldTouchValue < currentX)
            {
                flipper.ShowNext();
            }
            else if (oldTouchValue > currentX)
            {
                flipper.ShowPrevious();
            }
            break;      
    }
}

This allows me to navigate between the different views but I'd like to make it slide left/right

I've seen some Java examples on how to make it work, but not direct way to translate it to c#.

What's required to make the views slide and is there a way to define the animation in XML?
I'm able to make Activities slide in and out using animations defined in XML and calls to OverridePendingTransition, but I'm not sure how to apply that knowledge here.

解决方案

This allows me to navigate between the different views but I'd like to make it slide left/right

The ViewFlipper has, through its ViewAnimator class, some methods to set the animation for the in and out actions, setInAnimation() and setOutAnimation(). This are in the Android SDK but should have correspondence in MonoDroid(with which unfortunately I'm not familiar so I could be wrong). In order to have the desired animation simply use the two methods above to set the desired animations(either xml file or programmatically built Animation) and then call the showNext/Previous methods like you currently do.

You even have some slide animation in the Android SDK, but again I don't know if they are present in MonoDroid.

Update: Those methods are indeed available in Monodroid and exposed like this:

//Using one of the built in animations:
flipper.SetInAnimation(this, Android.Resource.Animation.SlideInLeft);
flipper.SetOutAnimation(this, Android.Resource.Animation.SlideOutRight);

//Using custom animations defined in XML
flipper.SetInAnimation(this, Resource.Animation.slide_in_right);
flipper.SetOutAnimation(this, Resource.Animation.slide_out_left);

这篇关于意见ViewFlipper之间的幻灯片动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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