android 颜色过渡动画效果,Android 动态渐变颜色,渐变动画,让渐变动起来

前言

最近一直想写个app,可是不知道想些啥,今天给大家分享一下 渐变动起来的效果

效果

ce43d11c9f23

GIF.gif

因为gif图比较大,所有不够清晰,这里给大家讲解一下

文章最后的最终效果图

ce43d11c9f23

GIF.gif

ce43d11c9f23

image.png

最初的渐变色是这个颜色,由紫色变为蓝色,我们暂时分为这两块颜色,右边紫色会不断变浅变成粉红、橙黄、深蓝最后变回来。左边深蓝也会不断加深变成深蓝,深紫,深褐然后变回

给人的错觉就是右边移动到左边,移动的过程不断变色

其实我们仔细分析一下,他就是改变了起始端和末端的颜色

分析

上面就简单的分析了一下,现在来彻底分析一下怎么做

写出一个xml布局,然后自定义一个全屏的LinearLayout

onDraw加ValueAnimator 动态改变LinearGradient渐变色

是不是很简单?

实验一

xml

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"/>

java

public class gradual extends View {

private int animatedValue;

private int colorEnd;

private int colorStart;

public gradual(Context context) {

super(context);

init();

}

public gradual(Context context, @Nullable AttributeSet attrs) {

super(context, attrs);

System.out.println(111);

init();

}

public void init() {

ValueAnimator animator=ValueAnimator.ofInt(0,255);

animator.setDuration(20000);

animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

@RequiresApi(api = Build.VERSION_CODES.O)

@Override

public void onAnimationUpdate(ValueAnimator animation) {

animatedValue = (int) animation.getAnimatedValue();

colorStart = Color.rgb(255-animatedValue,animatedValue,255-animatedValue);

colorEnd = Color.rgb(animatedValue,animatedValue,255-animatedVal

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值