2014-02-10 77 views
5

這是我的顏色列表:如何以編程方式設置android:angle屬性的GradientDrawable?

static ArrayList<Integer> colors; 
static { 
    colors = new ArrayList<Integer>(); 
    colors.add(Color.parseColor("#43CFCF")); 
    colors.add(Color.parseColor("#1C6E9B")); 
    colors.add(Color.parseColor("#AC88C0")); 
    colors.add(Color.parseColor("#EE5640")); 
    colors.add(Color.parseColor("#EFBF4D")); 
} 

這是我繪製數組:

static Drawable[] drawables; 
static { 
    drawables = new Drawable[5]; 
    drawables[0] = new GradientDrawable(Orientation.TL_BR, new int[]{colors.get(0), colors.get(1)}); 
    drawables[1] = new GradientDrawable(Orientation.TL_BR, new int[]{colors.get(1), colors.get(2)}); 
    drawables[2] = new GradientDrawable(Orientation.TL_BR, new int[]{colors.get(2), colors.get(3)}); 
    drawables[3] = new GradientDrawable(Orientation.TL_BR, new int[]{colors.get(3), colors.get(4)}); 
    drawables[4] = new GradientDrawable(Orientation.TL_BR, new int[]{colors.get(4), colors.get(0)}); 
} 

現在,我遍歷繪製[]和交叉淡入淡出的B/W第n和(n +1)可繪製,使用alpha動畫。

現在,這是我的佈局看起來像:

enter image description here

我的佈局爲長方形(GradientDrawable.Orientation:左上-BottomRight),但這種定位值未設置我的漸變線(顏色之間)從右上角綁定到矩形的左下角。如果我的佈局是SquareShape,它會很好地工作。因此,我想以編程方式設置每個GradientDrawable的角度(不能使用xml,因爲我在代碼中創建了drawables,否則我將不得不爲每個drawable創建5個xmls) 。

另外,如果我的方向是TL_BR,android:angle的值是如何工作的?角度是否隨參考(軸)向TL_BR線(0弧度)而變化。

請幫忙!

回答

0

嘗試:

drawables[0] = new GradientDrawable(GradientDrawable.Orientation.TL_BR, new int[]{colors.get(0), colors.get(1)});

相反的:

drawables[0] = new GradientDrawable(Orientation.TL_BR, new int[]{colors.get(0), colors.get(1)});

相關問題