如何从mainactivity调用ondraw方法

时间:2015-01-12 16:43:22

标签: android

public class MyActivity extends Activity {

Paint p;
com.example.lean.myapplication.keypaint keypain;

@Override

protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.list_fragment);
    Canvas canvas = null;
    keypain = new com.example.lean.myapplication.keypaint(this);
    keypain.ondraw(canvas);

}

我无法成功调用keypaint中的ondraw函数。我对编程技巧很陌生。希望可以有人帮帮我。非常感谢你

public class keypaint extends View {
Paint p;

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    p=new Paint();
    Bitmap b= BitmapFactory.decodeResource(getResources(), R.drawable.icon);
    p.setColor(Color.RED);
    canvas.drawBitmap(b, 0, 0, p);
}




public keypaint(Context context) {
    super(context);
}

}

0 个答案:

没有答案