ViewFlipper

Class Overview

Simple ViewAnimator that will animate between two or more views that have been added to it. Only one child is shown at a time. If requested, can automatically flip between each child at a regular interval.

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		float  oldTouchValue = 0;
		
	    switch (event.getAction()) {
	    //当用户的手指接触屏幕
	       
		case MotionEvent.ACTION_DOWN:
			oldTouchValue=event.getX();
			break;
         //当用户的手指接触 离开屏幕
		  case MotionEvent.ACTION_UP:
		        float currentX = event.getX();
		        if (oldTouchValue < currentX-100)
		        {
//		        	一个。。。。进入屏幕
		        	
		          mViewFlipper01.setInAnimation(AnimationHelper.inFromLeftAnimation());
		          mViewFlipper01.setOutAnimation(AnimationHelper.outToRightAnimation());
		          mViewFlipper01.showNext();
		        }
		        if (oldTouchValue > currentX)
		        {
		          mViewFlipper01.setInAnimation(AnimationHelper.inFromRightAnimation());
		          mViewFlipper01.setOutAnimation(AnimationHelper.outToLeftAnimation());
		          mViewFlipper01.showPrevious();
		        }
		        break;
		}
		
		
		
		
		return super.onTouchEvent(event);
		 
	}



import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;

public class AnimationHelper
{
  public static Animation inFromRightAnimation()
  {
    Animation inFromRight = new TranslateAnimation(
        Animation.RELATIVE_TO_PARENT, +1.0f, Animation.RELATIVE_TO_PARENT,
        0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT,
        0.0f);
    inFromRight.setDuration(350);
    inFromRight.setInterpolator(new AccelerateInterpolator());
    return inFromRight;
  }
  
  public static Animation outToLeftAnimation()
  {
    Animation outtoLeft = new TranslateAnimation(Animation.RELATIVE_TO_PARENT,
        0.0f, Animation.RELATIVE_TO_PARENT, -1.0f,
        Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f);
    outtoLeft.setDuration(350);
    outtoLeft.setInterpolator(new AccelerateInterpolator());
    return outtoLeft;
  }
  
  // for the next movement
  public static Animation inFromLeftAnimation()
  {
    Animation inFromLeft = new TranslateAnimation(Animation.RELATIVE_TO_PARENT,
        -1.0f, Animation.RELATIVE_TO_PARENT, 0.0f,
        Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f);
    inFromLeft.setDuration(350);
    inFromLeft.setInterpolator(new AccelerateInterpolator());
    return inFromLeft;
  }
  
  public static Animation outToRightAnimation()
  {
    Animation outtoRight = new TranslateAnimation(Animation.RELATIVE_TO_PARENT,
        0.0f, Animation.RELATIVE_TO_PARENT, +1.0f,
        Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f);
    outtoRight.setDuration(350);
    outtoRight.setInterpolator(new AccelerateInterpolator());
    return outtoRight;
  }
}


http://wang-peng1.iteye.com/blog/572892

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值