我正试图在视图的背景中绘制一些颜色。
颜色将被放置为线性梯度并且在不同的方向上。
所以我做了以下事情:
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;
}
我有每一个绘图从开始的颜色到透明,这样所有的渐变都是可见的。但问题是所有的颜色都没有显示出来。只有最后一种颜色是通过渐变绘制的。其余的都看不见了。
有人能帮我弄清楚如何混合和展示所有的颜色吗?
谢谢。阳光
创建LayerDrawable并混合它们:
private LayerDrawable getGradientDrawable(int color, Orientation orientation){
int[] colors = new int[] {color, Color.WHITE};
GradientDrawable drawable1 = new GradientDrawable(orientation, colors);
drawable1.setAlpha(125);
GradientDrawable drawable2 = new GradientDrawable();
drawable2.setStroke(4, Color.parseColor("#FFFFFF"));
drawable2.setColor(Color.TRANSPARENT);
return new LayerDrawable(new Drawable[]{drawable1 , drawable2});
}
放置在抽屉1顶部的抽屉2。