FrameAnimation
Introduction: 高性能播放 android 帧动画。避免 AnimationDrawable 带来的 OOM 问题。High performance Android Frame animation that can play 1080P frame animation on most devices
Tags:
FrameAnimation 是一个简洁流畅的高性能帧动画控件。 结合使用了 TextureView 和 BlobCache,逐帧解析与绘制,避免了多帧的情况下使用 Android 原生 AnimationDrawable 带来的 OOM 和卡顿问题。
详细介绍文章:OOM?高性能帧动画 FrameAnimation-TextureView 和 BlobCache
BlobCache 算法可以查看:
示例
添加配置
dependencies {
...
implementation 'com.hewuzhao.frameanimation:frameanimation:1.0.1'
...
}
使用方法
动画资源图片,在/res/drawable 下建立 xxx.xml 文件:
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:oneshot="false"
app:maxBytes="524288000"
app:maxEntries="100"
app:version="1">
<item
android:drawable="@drawable/big_00"
android:duration="60" />
<item
android:drawable="@drawable/big_01"
android:duration="60" />
<item
android:drawable="@drawable/big_02"
android:duration="60" />
<item
android:drawable="@drawable/big_03"
android:duration="60" />
<item
android:drawable="@drawable/big_04"
android:duration="60" />
<item
android:drawable="@drawable/big_05"
android:duration="60" />
<item
android:drawable="@drawable/big_06"
android:duration="60" />
....
</animation-list>
Attributes | format | describe |
---|---|---|
maxBytes | integer | BlobCache 缓存的最大容量,单位:字节 |
maxEntries | integer | BlobCache 缓存的资源个数 |
version | integer | BlobCache 版本号 |
在你的 xml 布局文件中使用:
<com.hewuzhao.frameanimation.frameview.FrameTextureView
android:id="@+id/frame_view"
android:layout_width="0dp"
android:layout_height="0dp"
app:src="@drawable/big_animation_drawable"
app:useCache="true" />
Attributes | format | describe |
---|---|---|
src | reference | res/drawable 下的资源列表 |
useCache | boolean | 开关:是否使用 BlobCache 缓存 |
启动帧动画:
FrameTextureView.startWithFrameSrc(R.drawable.xxx);
License
Copyright (C) hewuzhao, FrameAnimation Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.