Если вы развертываете в Windows, узел сценария Windows предлагает очень полезный JScript API для файловой системы и других локальных ресурсов. Однако включение сценариев WSH в локальное веб-приложение может быть не таким элегантным, как вы могли бы пожелать.
Попробуйте этот способ, загрузив GIF , используя Glide в вашем методе onDraw()
:
Редактировать: на основе обсуждения с [118 ] @filipst о загрузке его на холст, добавлении кода в метод onResourceReady()
@Override
protected void onDraw(Canvas canvas) {
...
Glide.with(this.getContext()) // 'this' here is your custom view reference
.asGif() // We will define this to tell Glide about it's GIF format to load explicitly
.load(R.raw.gif_test) // or even put it into drawable R.drawable.git_test
.into(new SimpleTarget<GifDrawable>() {
@Override
public void onResourceReady(@NonNull GifDrawable resource, @Nullable Transition<? super GifDrawable> transition) {
resource.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); // Import to set bounds of canvas to load resource otherwise won't load
resource.draw(canvas);
resource.start();
//or
resource.startFromFirstFrame();
}
});
...
}
Вы можете использовать Лотти здесь Библиотека
Из XML
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/animation_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:lottie_rawRes="@raw/hello_world"
// or
app:lottie_fileName="hello_world.json"
// Loop indefinitely
app:lottie_loop="true"
// Start playing as soon as the animation is loaded
app:lottie_autoPlay="true" />
Программно
@BindView(R.id.animation_view)
LottieAnimationView animation_view;
animation_view.setImageAssetsFolder("images/");
animation_view.setAnimation(R.raw.lightning_animation);
animation_view.useHardwareAcceleration(true);
animation_view.enableMergePathsForKitKatAndAbove(true);
animation_view.setScaleType(ImageView.ScaleType.CENTER_CROP);
animation_view.playAnimation();
Это легкая и простая библиотека для использования анимации, как GIF.