import android.view.View;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new Custview(this));
}
class Custview extends View{
Paint paint = new Paint();
public Custview(Context context) {
super(context);
test();
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
paint.setColor(Color.RED);
paint.setStrokeWidth(5);
canvas.drawCircle(100, 100, 90, paint);
}
void test(){
System.out.println("Test");
Toast.makeText(MainActivity.this, "Test", 1).show();
}
}
}
刚学玩安卓,api的问题真多,所以来这救助高手
class Custview extends View是mainactivity的内部类,
其继承了view对象,这个好理解,可是
setContentView(new Custview(this));
这句代码是怎么去调用class Custview里的onDraw呢?
我的猜想是view里的构造器调用了view里的onDraw方法,不知对不对?谢谢
|
|