作者: 真好吃哦 | 来源:发表于2018-05-11 13:35 被阅读0次

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-animatedValue);
                invalidate();
            }
        });
        animator.start();


}
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    //获取View的宽高
    int width = getWidth();
    int height = getHeight();

    Paint paint = new Paint();
    LinearGradient backGradient = new LinearGradient(width, 0, 0, 0, new int[]{colorStart,colorEnd}, new float[]{0,1f}, Shader.TileMode.CLAMP);
    paint.setShader(backGradient);

    canvas.drawRect(0, 0, width, height, paint);
}

}

相关文章

  • 他、他、他、他、他……

    他,正直而坦荡,直接亦暴躁,我被骂哭过。他在所有人面前高高在上,偶尔对我流露出一些善良的温柔——我执拗又天真的跟他...

  • 他他他他

  • 他 他 他 他 他 她

    起名字于我而言不算易事,尤其是标题。 跟T分开了。 见了K,现在算来我们是18年的朋友。 辞职备考阶段跟爹爹不长却...

  • 《他他他》

    我喜欢一个男孩子,我不知道为什么,就只是,只是看见他,就感觉好紧张,好像要把最好的一面给他看。都说喜欢上一个人,...

  • 他,他,他

    从小一直被别人羡慕,并不是因为我学习多好,长得多好看,多有才艺,只是因为有一个跟我相差八岁的哥哥……总是会听到那些...

  • 他,他,他

    晚上和新新闲聊,就说到了男朋友这个话题。新新不太喜欢我男票,总说颜不够。其实,我男票可以了,可能是情人眼里出西施吧...

  • 他他他

    他是我最爱的人 他也是最爱我的人 在他的庇护下我从未受过一丝委屈 他也曾在我失落时默默流泪 我看到了 听到了...

  • 他他他

    她爱上了他,他爱上了她。 你不是我喜欢的那种人,却成了我喜欢的那个人!

  • 他他他

    跟他出去玩,忽然想起那个他跟他。 上山时,想到的是跟他去天台山的情景,那时我们手牵手一路畅谈。同样别致的景点,我依...

  • 他 他 他

    一 骨瘦如柴 。 他瘦得—— 惊心动魄!​ 二 赤脚躺在横椅上—— 流浪汉​。 三 冷风中,他缩着手走过……

网友评论

      本文标题:

      本文链接:https://www.haomeiwen.com/subject/dksfdftx.html