How to create animated background gradient like Instagram app?

心不动则不痛 提交于 2019-12-18 11:36:49

问题


Below are screenshots of instagram app. The background keeps on transforming from one gradient to other very beautifully.

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


回答1:


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>

Transition Drawables in Android

TransitionDrawable trans = (TransitionDrawable) myLayout.getBackground();
trans.startTransition(2000);


来源:https://stackoverflow.com/questions/35439573/how-to-create-animated-background-gradient-like-instagram-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!