Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲

Android Activity 跳轉動畫效果整理

編輯:關於 Android 程式設計

Activity 轉場動畫

Android 原生的 Activity 切換較為生硬,但可利用 overridePendingTransition 指定進入與退出動畫,讓畫面切換更自然。

動畫資源

先在 res 下建立 anim 資料夾,將放大、縮小、淡入淡出或位移效果寫成 XML。

<set xmlns:android='https://schemas.android.com/apk/res/android'>
  <scale android:fromXScale='0.1' android:toXScale='1.0' android:duration='300' />
  <alpha android:fromAlpha='0.1' android:toAlpha='1.0' android:duration='300' />
</set>

呼叫方式

startActivity(new Intent(this, OtherActivity.class));
overridePendingTransition(R.anim.zoomin, R.anim.zoomout);

第一個參數是新頁面進入效果,第二個是目前頁面退出效果。搭配不同 XML,即可做出放大、淡入淡出、左右滑動等轉場。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved