代码如下:package wyf.ytl;import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;public class MyVeiw extends View{
Bitmap myBitmap;
Paint paint;
public MyVeiw(Context context, AttributeSet attrs) {
super(context, attrs);
this.initBitmap();
// TODO Auto-generated constructor stub
}
private void initBitmap() {
paint =new Paint();
myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.img);
// TODO Auto-generated method stub
}
protected void onDraw(Canvas canvas){
super.onDraw(canvas);
paint.setAntiAlias(true);
}
}执行顺序是什么??
个人觉得应该先MyVeiw,然后initBitmap,最后onDraw...
这样的话问题是onDraw哪里被调用了。。不是这样的话又是如何执行的!请高手帮忙
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;public class MyVeiw extends View{
Bitmap myBitmap;
Paint paint;
public MyVeiw(Context context, AttributeSet attrs) {
super(context, attrs);
this.initBitmap();
// TODO Auto-generated constructor stub
}
private void initBitmap() {
paint =new Paint();
myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.img);
// TODO Auto-generated method stub
}
protected void onDraw(Canvas canvas){
super.onDraw(canvas);
paint.setAntiAlias(true);
}
}执行顺序是什么??
个人觉得应该先MyVeiw,然后initBitmap,最后onDraw...
这样的话问题是onDraw哪里被调用了。。不是这样的话又是如何执行的!请高手帮忙
解决方案 »
- 求助:请高手提供一个基于OpenCV-Android的Eclipse项目作为参考!
- 设置背景图片的问题
- Android给我们带来的是什么?机遇?挑战?未来?
- 一个framelayout中嵌套一个linearlayout有什么意义?
- 怎么样实现 “音频 变声”
- handler里的问题
- [求助]main.xml点开后,控件面板里大都数控件不能用
- 模拟器安装apk失败 Installation error: INSTALL_FAILED_CONTAINER_ERROR
- Mac系统AndroidStudio ADM 打不开出现错误日志
- android怎么实现代码输入,显示不同颜色
- android jni
- Android 手机客户端与J2EE服务器之间https连接的问题
哥。上层调用。。你是指这里?super(context, attrs);?
问题是上层调用了也是再this.initBitmap();之前。。
变量paint没有new可用?请解释的清楚点谢谢。带上执行顺序。。
Invalidate the whole view. If the view is visible, onDraw will be called at some point in the future. This must be called from a UI thread. To call from a non-UI thread, call postInvalidate().
你继承了view类onDraw 自然就会执行。你要看谁先执行,直接打印一些数据看看就知道了。
调用invalidate()会进ondraw()方法