Android : mixing two gradient drawable for a view in android

on Friday, September 26, 2014


I am trying to draw some colors in the background of a view.


The colors are to be placed as linear gradients and in different directions.


So i did the following:



private Orientation[] orientations = new Orientation[]{Orientation.BL_TR, Orientation.BR_TL, Orientation.TL_BR, Orientation.TR_BL, Orientation.TOP_BOTTOM};
public void drawBackgroudGradient(RelativeLayout backgroundView, int[] colors){
if (colors != null){
if (colors.length > 1){
for (int i=0; i<colors.length; i++){
backgroundView.setBackgroundDrawable(getGradientDrawable(colors[i], orientations[i]));
}
}else{
//in case of only one color just set that color as background
backgroundView.setBackgroundColor(colors[0]);
}
}
}

private GradientDrawable getGradientDrawable(int color, Orientation orientation){
int[] colors = new int[] {color, Color.WHITE};

GradientDrawable drawable = new GradientDrawable(orientation, colors);
drawable.setAlpha(125);
return drawable;
}


I have each drawable going from the starting color to transparent so that all the gradients are visible. But the problem is that all the colors are not showing up. Only the last color is drawn via the gradient drawable. the rest can not be seen.


Could someone please help me figure out how to mix and show all the colors?


Thanks. Sunny


0 comments:

Post a Comment