本文介绍了多颜色的进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个进度条(中间的进度条)类似的Gmail应用程序,它改变colours.I我能够这样通过保持和SDK /平台更新progress_indeterminate_horizo​​ntal.xml。我不希望使用动画(多彩色图像)。我想要实现这个使用XML(我想用梯度)。任何帮助将AP preciated。

I want to create a progress bar (intermediate progress bar) similar to gmail app which change colours.I am able to this by keeping and updating progress_indeterminate_horizontal.xml from sdk/platforms. I don't want to use animation (multi colour images). I want to achieve this using xml (i want use gradient). Any help will be appreciated.

在此先感谢

推荐答案

下面是我的实现:绘制动画彩虹渐变。酷,如果我不这样说我自己。它不是基于XML的,但可以被制成,它也使用渐变。也许它会给你一些想法。

Here's my implementation: Draws an animated rainbow gradient. Cool, if I do say so myself. It's not XML-based, but could be made to be, and it does use gradients. Perhaps it will give you some ideas.

设置:

    pb = (ProgressBar) findViewById(R.id.progressbar_Horizontal);
    GradientDrawable rainbow = new GradientDrawable(Orientation.LEFT_RIGHT,
            new int[] {Color.RED, Color.MAGENTA, Color.BLUE, Color.CYAN, Color.GREEN, Color.YELLOW, Color.RED});

    AnimationDrawable ad = getProgressBarAnimation();
    pb.setBackgroundDrawable(ad);

和动画:

    private AnimationDrawable getProgressBarAnimation(){

    GradientDrawable rainbow1 = new GradientDrawable(Orientation.LEFT_RIGHT,
            new int[] {Color.RED, Color.MAGENTA, Color.BLUE, Color.CYAN, Color.GREEN, Color.YELLOW});

    GradientDrawable rainbow2 = new GradientDrawable(Orientation.LEFT_RIGHT,
            new int[] { Color.YELLOW, Color.RED, Color.MAGENTA, Color.BLUE, Color.CYAN, Color.GREEN});

    GradientDrawable rainbow3 = new GradientDrawable(Orientation.LEFT_RIGHT,
            new int[] { Color.GREEN, Color.YELLOW, Color.RED, Color.MAGENTA, Color.BLUE, Color.CYAN });

    GradientDrawable rainbow4 = new GradientDrawable(Orientation.LEFT_RIGHT,
            new int[] { Color.CYAN, Color.GREEN, Color.YELLOW, Color.RED, Color.MAGENTA, Color.BLUE });

    GradientDrawable rainbow5 = new GradientDrawable(Orientation.LEFT_RIGHT,
            new int[] { Color.BLUE, Color.CYAN, Color.GREEN, Color.YELLOW, Color.RED, Color.MAGENTA });

    GradientDrawable rainbow6 = new GradientDrawable(Orientation.LEFT_RIGHT,
            new int[] {Color.MAGENTA, Color.BLUE, Color.CYAN, Color.GREEN, Color.YELLOW, Color.RED });


    GradientDrawable[]  gds = new GradientDrawable[] {rainbow1, rainbow2, rainbow3, rainbow4, rainbow5, rainbow6};

    AnimationDrawable animation = new AnimationDrawable();

    for (GradientDrawable gd : gds){
        animation.addFrame(gd, 100);

    }

    animation.setOneShot(false);

    return animation;


}

这篇关于多颜色的进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 06:53