手機應用上有很多地方需要用到動畫的地方,比如啓動頁面歡迎界面等,有些動畫比如簡單的伸縮旋轉等我們可以用屬性動畫來製作,但是涉及到一些複雜的不規則的動畫我們要實現起來就很麻煩,但是利用lottie加載json格式文件就簡單的很多了。json格式文件的動畫是利用AE工具製作然後通過插件bodymovin轉換成json格式。
先附上資源,親測可用。
AE工具:http://pan.baidu.com/s/1hsJrKCs,裏面有AE cc 2015,據說只有cc2015纔可以用bodymovin插件。還有一個Adobe_pojie.exe文件,它是破解工具,找到相應版本,然後將安裝文件裏面的dll文件替換即可。還有一個文件夾是ExManCmd_win,它是安裝插件bodymovin所需要的(已經將bodymovin文件放在裏面,不需要從github上下載https://github.com/bodymovin/bodymovin)。
Lottie開源庫:https://github.com/airbnb/lottie-android。
1. 安裝AE
2. 安裝bodymovin插件
- 管理員權限運行cmd
- cd到ExManCmd_win文件夾位置
- 輸入“ ExManCmd.exe
/install bodymovin.zxp”回車就完成了
可以打開AE看到如圖所示有bodymovin表示安裝插件成功:
通過xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.airbnb.lottie.LottieAnimationView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:lottie_fileName="data.json"
app:lottie_autoPlay="true"
app:lottie_loop="true"
/>
</LinearLayout>
通過代碼:LottieAnimationView animationView = (LottieAnimationView) findViewById(R.id.animation_view);
animationView.setAnimation("data.json");
animationView.loop(true);
生成的動畫效果: