我正在尝试通过堆栈流中的一个成员告知渐变文本 下面是我的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 :(得分: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
}