AnimatedVectorDrawable作为窗口背景.是否有可能? [英] AnimatedVectorDrawable as Window background. Is it possible?

查看:100
本文介绍了AnimatedVectorDrawable作为窗口背景.是否有可能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用AnimatedVectorDrawable作为放置在窗口背景中的启动动画.我使用 https://developer.android.com/中给出的官方示例参考/android/graphics/drawable/AnimatedVectorDrawable.html .它出现但没有动画.

I'm trying to use AnimatedVectorDrawable as a splash animation placed in the window background. I use the official example given in https://developer.android.com/reference/android/graphics/drawable/AnimatedVectorDrawable.html. It appears but doesn't animate.

是否完全可以在Window背景中制作动画?

Are animations in a Window background possible at all?

推荐答案

首次打开应用程序(冷启动)时看到的第一个屏幕是WindowManager创建的屏幕占位符.它通过获取您在主题上设置的资源(例如窗口背景和状态栏颜色)来创建占位符.要启动窗口背景的动画,您必须调用其start()方法,但是WindowManager是您几乎无法控制的系统服务.因此,在应用程序初始化的这一阶段,除非在Application.onCreate()方法中使用某些晦涩的方法来控制WindowManager,否则无法对矢量背景进行动画处理.

The first screen that you see when opening an app for the first time (cold start) is a screen placeholder create by the WindowManager. It creates the placeholder by getting resources that you set on your theme, like the window background and status bar color. To start the animation of your window background you have to call its start() method, but the WindowManager is a system service that you have little or no control over. So on this phase of application initialisation, unless there is some obscure way to control the WindowManager in the Application.onCreate() method, it is not possible to animate the vector background.

我从冷启动中打开了很多我的应用程序,包括Google的应用程序,似乎没有一个应用程序在冷启动阶段实现动画(例如Material Design的文档暗示可能).在主要活动的onCreate冷启动后,很少有动画制作.

I opened from cold start a lot of my apps including Google ones and not a single one seems to implement animations on the cold start phase (like the docs of Material Design imply possible). A very few make animations after the cold start at the onCreate of the main activity.

如果没问题,可以在冷启动后开始播放动画,例如将徽标移到屏幕顶部的情况下,您可以:

If it's not a problem start the animation after he cold start, like in the case of moving the logo to the top of the screen, you can:

  1. 在AndroidManifest.xml的启动活动中,将属性为android:windowBackground的主题设置为静态可绘制对象
  2. 在活动"中调用super.onCreate()之前,请将主题更改为默认主题.
  3. 在静态窗口背景矢量的同一位置使用AnimatedVectorDrawable的ImageView设置内容视图.
  4. 调用AnimatedVectorDrawable的start()方法.
  1. Set a theme with attribute android:windowBackground to your static drawable at your launch activity in AndroidManifest.xml
  2. Before call super.onCreate() in your Activity, change the theme for your default theme.
  3. Set a content view with a ImageView of your AnimatedVectorDrawable at the same position of your static window background vector.
  4. Call start() method of your AnimatedVectorDrawable.

这是 AndroidDeveloper的帖子,详细说明了如何处理启动屏幕的应用程序主题

这篇关于AnimatedVectorDrawable作为窗口背景.是否有可能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆