码迷,mamicode.com
首页 > 其他好文 > 详细

界面切换动画效果

时间:2014-05-12 10:00:20      阅读:372      评论:0      收藏:0      [点我收藏+]

标签:android   tar   ext   c   http   int   

private ViewFlipper flipper;    

private float startX;    

private Animation in_lefttoright;    

private Animation outlefttoright;        

private Animation in_righttoleft;    

private Animation out_righttoleft;    

@Override    

public void onCreate(Bundle savedInstanceState) {        

super.onCreate(savedInstanceState);        

setContentView(R.layout.main);                

flipper = (ViewFlipper) this.findViewById(R.id.viewFlipper);                

in_lefttoright = AnimationUtils.loadAnimation(this, R.anim.in_lefttoright);        

outlefttoright = AnimationUtils.loadAnimation(this, R.anim.out_lefttoright);                

in_righttoleft = AnimationUtils.loadAnimation(this, R.anim.in_righttoleft);        

out_righttoleft = AnimationUtils.loadAnimation(this, R.anim.out_righttoleft);    

}

 

@Override  

public boolean onTouchEvent(MotionEvent event) {   

  switch (event.getAction()) {   

    case MotionEvent.ACTION_DOWN:    

      startX = event.getX();    

      break;

      case MotionEvent.ACTION_UP:    

      float endX = event.getX();    

      if(endX > startX){

        //向右     

        flipper.setInAnimation(in_lefttoright);     

        flipper.setOutAnimation(outlefttoright);     

        flipper.showNext();

        //显示下一页    

      }else if(endX < startX){

        //向左     

        flipper.setInAnimation(in_righttoleft);     

        flipper.setOutAnimation(out_righttoleft);     

        flipper.showPrevious();    

      }    

      break;   

    }   

    return super.onTouchEvent(event);  

  }    

}

 

main.xml主布局文件:

  <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
 <ViewFlipper 
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:id="@+id/viewFlipper"
     >
     <!-- 第一页 -->
     <LinearLayout
     android:orientation="vertical"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     >
      <TextView
       android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="第一屏"
      />
      
     </LinearLayout>
     
     <!-- 第二页 -->
     <LinearLayout
     android:orientation="vertical"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:background="#FFFFFF"
     >
      <TextView
       android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="第二屏"
      />
      
     </LinearLayout>
    </ViewFlipper>
</LinearLayout>

 

in_lefttoright.xml文件:

  

<set xmlns:android="http://schemas.android.com/apk/res/android"     android:shareInterpolator="false">  

<translate        

  android:fromXDelta="-100%p"                

  android:toXDelta="0"                

  android:duration="3000"         />

</set>

 

in_righttoleft.xml文件:

  

<set xmlns:android="http://schemas.android.com/apk/res/android"     android:shareInterpolator="false">  

<translate        

  android:fromXDelta="100%p"              

    android:toXDelta="0"                

  android:duration="3000"         />

</set>

 

out_lefttoright.xml文件:

  

<set xmlns:android="http://schemas.android.com/apk/res/android"    

  android:shareInterpolator="false">  

  <translate        

    android:fromXDelta="0"                

    android:toXDelta="100%p"                

    android:duration="3000"         />

</set>

out_righttoleft.xml文件:

 

  

<set xmlns:android="http://schemas.android.com/apk/res/android"    

  android:shareInterpolator="false">  

  <translate         android:fromXDelta="0"                

          android:toXDelta="-100%p"                

        android:duration="3000"         />

</set>

 

 

 

界面切换动画效果,布布扣,bubuko.com

界面切换动画效果

标签:android   tar   ext   c   http   int   

原文地址:http://www.cnblogs.com/fenglh04/p/3720638.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!