将帧速率设置为 ViewSwitcher alpha 动画

Set frame rate to ViewSwitcher alpha animation

我有带两个 ImageView 的 ViewSwitcher。它有交叉淡入淡出动画(第一次出现,另一个消失)。使用 AlphaAnimation

完成
viewSwitcher.setInAnimation(inAlphaAnimation);
viewSwitcher.setOutAnimation(fadeAlphaAnimation);

非常流畅漂亮。但是我想从中制作 gif,所以我从布局中截取了屏幕截图 "catch frames" 并从中创建了一个 gif。一切都很好。但是我需要动画本身像一个有帧率的gif,所以它不会很流畅。有可能达到这样的效果吗? 谢谢。

您可以使用硬件层改进动画以应用

http://blog.danlew.net/2015/10/20/using-hardware-layers-to-improve-animation-performance/

希望这对您有所帮助..

我搜索了更多,发现了这个: https://developer.android.com/guide/topics/graphics/prop-animation.html

Frame refresh delay: You can specify how often to refresh frames of your animation. The default is set to refresh every 10 ms, but the speed in which your application can refresh frames is ultimately dependent on how busy the system is overall and how fast the system can service the underlying timer.

我发现了这个为所有动画设置帧速率的方法:

ValueAnimator.setFrameDelay(长帧延迟);

希望这对其他人有帮助)