2012-02-03 80 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 






}