android– 渐变色动画

android– 渐变色动画,第1张

概述我想要实现的目标:径向渐变,开始和结束颜色随着时间的推移从一种定义的颜色到另一种颜色的平滑变化.到目前为止我尝试过的:像这样使用ObjectAnimator:searchAnimator=ObjectAnimator.ofFloat(drawThread,newProperty<DrawThread,Float>(Float.TYPE,"fraction"){

我想要实现的目标:

径向渐变,开始和结束颜色随着时间的推移从一种定义的颜色到另一种颜色的平滑变化.

到目前为止我尝试过的:

像这样使用ObjectAnimator:

        searchAnimator = ObjectAnimator.offloat(drawThread, new Property<DrawThread, float>(float.TYPE, "fraction") {            @OverrIDe            public float get(DrawThread object) {                return object.fraction;            }            @OverrIDe            public voID set(DrawThread object, float value) {                object.setFraction(value);            }        }, 0, 1);        searchAnimator.setDuration(maxSearchDuration);        searchAnimator.setInterpolator(new linearInterpolator());

这将调用DrawThread.setFraction(value);随着时间的推移.在线程内部,我使用SurfaceVIEw执行Canvas绘图,如下所示:

mPaint = new Paint(Paint.ANTI_AliAS_FLAG);mPaint.setDither(true);mPaint.setStyle(Paint.Style.FILL_AND_stroke);radius = (int) Math.sqrt(canvas.getWIDth() / 2 * canvas.getWIDth() / 2 + canvas.getHeight() / 2 * canvas.getHeight() / 2);//calculating colors for current fraction using ARGBEvaluatorint start = (int) argbEvaluator.evaluate(fraction, colors[0].start, colors[1].start);int end = (int) argbEvaluator.evaluate(fraction, colors[0].end, colors[1].end);//endmPaint.setShader(new RadialGradIEnt(canvas.getWIDth() / 2, canvas.getHeight() / 2,      radius, start, end, Shader.TileMode.CLAMP));canvas.drawCircle(canvas.getWIDth() / 2, canvas.getHeight() / 2, radius, mPaint);

问题:

>渐变不平滑.图像看起来像低色
>性能非常低.我在FullHD Snapdragon 801设备上得到aprox 16 FPS.

所以我想问的是提高性能(甚至是完全不同的方式)以及提高最终图像质量的任何帮助.

解决方法:

您可以像这样设置渐变中的颜色变化:

int colorFrom = ContextCompat.getcolor(this, R.color.red);int colorTo = ContextCompat.getcolor(this, R.color.blue);ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);colorAnimation.setDuration(2000);int color1 = ContextCompat.getcolor(this, R.color.red);int color2 = ContextCompat.getcolor(this, R.color.green);GradIEntDrawable gradIEntDrawable = new GradIEntDrawable(            GradIEntDrawable.OrIEntation.top_BottOM, new int[]{color1, color2});gradIEntDrawable.setGradIEntType(GradIEntDrawable.RADIAL_GRADIENT);colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {        @OverrIDe        public voID onAnimationUpdate(ValueAnimator animator) {            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LolliPOP) {                gradIEntDrawable.setcolors(new int[]{(int) animator.getAnimatedValue(), color2});                vIEwWithGradIEntBg.setBackground(gradIEntDrawable);            }        }    });colorAnimation.start();
总结

以上是内存溢出为你收集整理的android – 渐变色动画全部内容,希望文章能够帮你解决android – 渐变色动画所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1117185.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存