0

我想用 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 帮助将不胜感激.....

4

1 回答 1

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);
  }
}
于 2012-12-04T08:40:38.670 回答