網站首頁 編程語言 正文
幀動畫
幀動畫就是給定一個完整動畫的所有關鍵幀,由大腦想象中間的變化過程的一種動畫。
<?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false"> <item android:drawable="@drawable/ic_loading_0" android:duration="100"/> <item android:drawable="@drawable/ic_loading_1" android:duration="100"/> <item android:drawable="@drawable/ic_loading_2" android:duration="100"/> <item android:drawable="@drawable/ic_loading_3" android:duration="100"/> <item android:drawable="@drawable/ic_loading_4" android:duration="100"/> <item android:drawable="@drawable/ic_loading_5" android:duration="100"/> <item android:drawable="@drawable/ic_loading_6" android:duration="100"/> <item android:drawable="@drawable/ic_loading_7" android:duration="100"/> </animation-list>
將這個xml文件放到drawable文件夾下,就可以引用上了。
補間動畫
補間動畫就是指定動畫開始和結束的狀態,中間的變化,由計算機自動補齊。補間動畫有4種類型,平移動畫(Translate)、透明度動畫(Alpha)、旋轉動畫(Rotate)、縮放動畫(Scale)。
旋轉動畫
<?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="1000" android:fillAfter="true" android:fromDegrees="0" android:pivotX="50%" android:pivotY="50%" android:repeatCount="1" android:toDegrees="180"> </rotate>
透明度動畫
<?xml version="1.0" encoding="utf-8"?> <alpha xmlns:android="http://schemas.android.com/apk/res/android" android:duration="1000" android:fromAlpha="1.0" android:toAlpha="0.5"> </alpha>
平移動畫
<?xml version="1.0" encoding="utf-8"?> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="1000" android:fromXDelta="0" android:fromYDelta="0" android:toXDelta="100%" android:toYDelta="100%"> </translate>
縮放動畫
<?xml version="1.0" encoding="utf-8"?> <scale xmlns:android="http://schemas.android.com/apk/res/android" android:duration="1000" android:fromXScale="1.0" android:fromYScale="1.0" android:toXScale="1.2" android:toYScale="1.2" android:pivotX="50%" android:pivotY="50%"> </scale>
屬性動畫
屬性動畫,就是監聽一個屬性的變化值,來完成的動畫。簡言之,就是不斷修改該對象的某個屬性值,然后讓動畫框架來監聽它。
ValueAnimator
ValueAnimator.ofFloat(0f, 1f)
創建一個從0逐漸變化到1點動畫。
ObjectAnimator
new ObjectAnimator().addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationCancel(Animator animation) {
super.onAnimationCancel(animation);
}
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
}
@Override
public void onAnimationRepeat(Animator animation) {
super.onAnimationRepeat(animation);
}
@Override
public void onAnimationStart(Animator animation) {
super.onAnimationStart(animation);
}
@Override
public void onAnimationPause(Animator animation) {
super.onAnimationPause(animation);
}
@Override
public void onAnimationResume(Animator animation) {
super.onAnimationResume(animation);
}
});
監聽動畫的狀態。
TypeEvaluator估值器
public interface TypeEvaluator<T> {
/**
* This function returns the result of linearly interpolating the start and end values, with
* <code>fraction</code> representing the proportion between the start and end values. The
* calculation is a simple parametric calculation: <code>result = x0 + t * (x1 - x0)</code>,
* where <code>x0</code> is <code>startValue</code>, <code>x1</code> is <code>endValue</code>,
* and <code>t</code> is <code>fraction</code>.
*
* @param fraction The fraction from the starting to the ending values
* @param startValue The start value.
* @param endValue The end value.
* @return A linear interpolation between the start and end values, given the
* <code>fraction</code> parameter.
*/
public T evaluate(float fraction, T startValue, T endValue);
}
使用估值器來計算兩個邊緣狀態的所有中間值。
ObjectAnimator.ofObject(target, propertyName, evaluator, values);
target參數為監聽的對象,propertyName為監聽的該對象的某個屬性的名字,也可以監聽該屬性的setXxx()方法。evaluator傳入一個估值器,values為你要估值的所有關鍵的點的值,然后通過這些給定的點,來估計一定時間內這個點在中間時刻的值。
Interpolator插值器
public interface Interpolator extends TimeInterpolator {
// A new interface, TimeInterpolator, was introduced for the new android.animation
// package. This older Interpolator interface extends TimeInterpolator so that users of
// the new Animator-based animations can use either the old Interpolator implementations or
// new classes that implement TimeInterpolator directly.
}
用它的實現類來決定動畫的變化速率,比如先快后慢、先慢后快、勻速等。比較常用的有LinearInterpolator(勻速)、AccelerateInterpolator(加速)、DecelerateInterpolator(減速)。ValueAnimator和ObjectAnimator都可以通過調用
public abstract void setInterpolator(TimeInterpolator value);
設置插值器,因為這個方法是Animator抽象類的。
原文鏈接:https://juejin.cn/post/7192874735607218233
相關推薦
- 2022-06-07 Python接口自動化之文件上傳/下載接口詳解_python
- 2022-11-30 CTF?AWD入門學習手冊_安全相關
- 2023-12-07 ant 循環多條通知提醒框堆疊問題
- 2023-01-23 Python操作MongoDB增刪改查代碼示例_python
- 2022-05-05 Python學習之流程控制與條件判斷總結_python
- 2022-04-17 WPF框架Prism中ViewModelLocator用法介紹_基礎應用
- 2022-04-25 ASP.NET?Core?MVC中Tag?Helpers用法介紹_實用技巧
- 2022-09-01 PgSQL條件語句與循環語句示例代碼詳解_PostgreSQL
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支