Home >Web Front-end >HTML Tutorial >activity switching animation and page switching animation_html/css_WEB-ITnose
Activity switching animation
To achieve Activity switching animation, you need to rely on overridePendingTransition. There are two parameters in it: the animation when entering the Activity and the animation when leaving the Activity.
It should be noted that it must be called immediately after StartActivity() or finish()
For example, if there is a Button in MainActivity, the code to jump to OtherActivity after clicking the Button is as follows:
Intent intent = new Intent(this, OtherActivity.class); startActivity(intent); this.overridePendingTransition(R.anim.enteralpha, R.anim.exitalpha);
Interface switching animation
Interface switching animation relies on ViewFlipper to implement
<ViewFlipper android:id="@+id/view_flipper" android:layout_width="match_parent" android:layout_height="match_parent" > <!-- 第一页 --> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="#009900" android:orientation="vertical" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="第一页" /> </LinearLayout> <!-- 第二页 --> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ffff00" android:orientation="vertical" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="第二页" /> </LinearLayout> </ViewFlipper>
@Override public boolean onTouchEvent(MotionEvent event) { // TODO Auto-generated method stub if (event.getAction() == MotionEvent.ACTION_DOWN) { startX = event.getX(); } else if (event.getAction() == MotionEvent.ACTION_UP) { float endX = event.getX(); if (endX > startX ) { flipper.showNext();// 显示下一页 } else if (endX<startX) { flipper.showPrevious();// 显示前一页 } return true; } return super.onTouchEvent(event); }