2012-02-03 120 views
0

我想實現梯度文本在堆棧中的成員之一,因爲告訴流 下面是我的MainActivity類別,我打電話給我的Draw2D的類,它繪製在畫布爲什麼這個梯度不工作

public class TextEffectsActivity extends Activity { 
/** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    TextView secondTextView = new TextView(this);  
    secondTextView.setText(R.id.textView6); 

    Draw2d d = new Draw2d(this, secondTextView); 
    // setContentView(R.layout.main); 
    setContentView(d); 
} 

這裏是我在Draw2D類在哪裏檢查代碼的結尾梯度我使用着色器

public class Draw2d extends View{ 

    TextView secondTextView; 
    public Draw2d(Context context, TextView tv) { 
    // TODO Auto-generated constructor stub 
    super(context); 
    secondTextView=tv;   
    }  
    protected void onDraw(Canvas canvas) 
    {   
     super.onDraw(canvas); 
     canvas.drawColor(R.color.VeryLightGrey);   
     Paint p = new Paint(); 

    // For gradient in text 
     Shader textShader=new LinearGradient(0, 0, 0, 0,new int[]{Color.YELLOW,Color.CYAN}, 
      null, TileMode.CLAMP); // null or new float[]{0.5f,1.0f} 
     secondTextView.getPaint().setShader(textShader);   
} 

回答

0

,我認爲你應該做的描繪顏色,前

protected void onDraw(Canvas canvas) 
{ 

    super.onDraw(canvas); 
    Paint p = new Paint(); 

    Shader textShader=new LinearGradient(0, 0, 0, 0, 
      new int[]{Color.YELLOW,Color.CYAN}, 
      null, TileMode.CLAMP);   // null or new  float[]{0.5f,1.0f} 
    secondTextView.getPaint().setShader(textShader); 
    canvas.drawColor(R.color.VeryLightGrey); 


    // For gradient in text 






}