为什么即使我在canvas对象上使用drawPath()也不显示circle?

时间:2012-10-25 09:55:32

标签: android canvas

我想用2D api进行一些编程,我做了一些编码,但事情是输出没有来。我的代码吼叫......

 public class GraphicprojectActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.main);
        setContentView(new MyView(this));
    }
    public class MyView extends View{
        public MyView(Context c1){
            super(c1);
        }
    }
    public void onDraw(Canvas c2){
        Path p1=new Path();
        Paint p2= new Paint();
        p2.setColor(Color.BLUE);
        p1.addCircle(100, 100, 300, Direction.CW);
        c2.drawPath(p1, p2);
    }
}

logcat中没有错误.. UR帮助会赞赏.....

1 个答案:

答案 0 :(得分:1)

你的onDraw方法在MyView类之外。您需要覆盖MyView的onDraw方法。

public class MyView extends View{
    public MyView(Context c1){
        super(c1);
    }
public void onDraw(Canvas c2){
    Path p1=new Path();
    Paint p2= new Paint();
    p2.setColor(Color.BLUE);
    p1.addCircle(100, 100, 300, Direction.CW);
    c2.drawPath(p1, p2);
  }
}