Q:

How can I create a Line with different colors in android

I want to create a line with different colors in two ways like:
1. ColorBar (preview)
Something like a progress bar but with different colors
2.Colorful Table (preview)
Something like a table but with different colors(not different cell background)
I want to for example write some code and say the min and max point of the periods and it show me the period in some color (like red) on a line.
so is there any way that I can draw them in my jar file?(I mean the jar file that is connected to activity like MainActivity.jar)
I use Android Studio v 1.0.2
Thanks for your useful helps:)

A:

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

The docs tell you how to set shape, interpolation between colors, position of colors, etc.

