2011-11-18 57 views
0

我想在黑莓中顯示垂直漸變作爲ListField Row的背景。我已經使用shadedFillPath功能來實現這一點,但沒有成功垂直漸變到黑莓ListFieldItem

int[] cols = new int[]{0xFFFFFF, 0xEEEEEE,0xEEEEEE,0XDDDDDD }; 
int[] xInds = new int[]{0, Display.getWidth(), Display.getWidth(), 0}; 
int[] yInds = new int[]{focusRect.y, focusRect.y,  
this.getRowHeight()+focusRect.y,this.getRowHeight()+focusRect.y}; 
graphics.drawShadedFilledPath(xInds, yInds,null, cols, null); 

回答

1

試試這個

 int[] X_PTS = { 0, getPreferredWidth(),getPreferredWidth(),0};   
     int[] Y_PTS = { 0,0, getPreferredHeight(),getPreferredHeight()};   
     int[] drawColors = { Colors.CategoryFocusGradientStart, Colors.CategoryFocusGradientStart, 
          Colors.CategoryFocusGradientEnd, Colors.CategoryFocusGradientEnd };   
     try {    
      g.drawShadedFilledPath(X_PTS, Y_PTS, null, drawColors, null);   
     } catch (IllegalArgumentException e) { 
      Log.Error(e,this,"Bad arguments."); 
     } 
0

它不是@ rfsk2010答案,但近(你必須更改0對Y):

分爲:

public void drawListRow(ListField listField, Graphics graphics,int index, int y, int width) 

這樣做:

int[] X_PTS = { 0, getPreferredWidth(),getPreferredWidth(),0};   
int[] Y_PTS = { y, y, getPreferredHeight(),getPreferredHeight()};   
int[] drawColors = { Colors.CategoryFocusGradientStart, Colors.CategoryFocusGradientStart, 
        Colors.CategoryFocusGradientEnd, Colors.CategoryFocusGradientEnd };   
try {    
    graphics.drawShadedFilledPath(X_PTS, Y_PTS, null, drawColors, null);   
} catch (IllegalArgumentException e) { 
    Log.Error(e,this,"Bad arguments."); 
}