如何像 Instagram 应用程序一样创建动画背景渐变? [英] How to create animated background gradient like Instagram app?
问题描述
以下是 Instagram 应用的截图.背景不断地从一个渐变过渡到另一个非常漂亮.
Below are screenshots of instagram app. The background keeps on transforming from one gradient to other very beautifully.
我想知道我怎样才能做到这一点.是否有任何代码可以自动为渐变设置动画,或者我是否需要添加具有轻微变化的不同渐变,如果我使用它不会对 Instagram 造成任何版权问题?我曾尝试使用多个渐变文件进行动画处理,使用帧动画略有变化,但它不平滑且效果不佳.谢谢
I want to know how can I achieve this. IS THERE ANY CODE TO ANIMATE A GRADIENT AUTOMATICALLY OR DO I NEED TO ADD DIFFERENT GRADIENTS WITH SLIGHT VARIATION, and if I use it won't cause any copyright issues with Instagram? I have tried animating using multiple gradient files with slight variation using Frame Animation but it isn't smooth and doesn't work well. Thanks
推荐答案
创建一个 TransitionDrawable 以在用作背景的两个可绘制对象之间进行切换.
Create a TransitionDrawable to change between two drawables that you use for the background.
<?xml version="1.0" encoding="UTF-8"?>
<transition xmlns:android="http://schemas.android.com/apk/res/android">
<!-- use whatever drawables you want, gradients, shapes etc-->
<item android:drawable="@drawable/start" />
<item android:drawable="@drawable/end" />
</transition>
TransitionDrawable trans = (TransitionDrawable) myLayout.getBackground();
trans.startTransition(2000);
这篇关于如何像 Instagram 应用程序一样创建动画背景渐变?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!