SurfaceView 也是继承自 View
而View 要刷新 就可以调用 invalidate
看你的代码 你是在看 LunarLander 这个例子~~~~~~~http://blog.csdn.net/l417584711/archive/2010/04/14/5485478.aspx
上面是我的博客 里面有一个简单的例子(本来能更简单点,但是无所谓,现在的也不难,就是有些没用的代码)
看看 能更好的理解怎么实现动画
而View 要刷新 就可以调用 invalidate
看你的代码 你是在看 LunarLander 这个例子~~~~~~~http://blog.csdn.net/l417584711/archive/2010/04/14/5485478.aspx
上面是我的博客 里面有一个简单的例子(本来能更简单点,但是无所谓,现在的也不难,就是有些没用的代码)
看看 能更好的理解怎么实现动画
解决方案 »
- 为什么我的安卓模拟器打开了 但不显示内容 小白求解 急
- android 中在自定义视图中使用自定义变量,额。。。分享下。
- 分享在广州干android的工资
- 安卓开发使用post传值为什么接收不到返回值,返回值那条语句根本就打印,url不方便透露,是正确的
- 如何在内部类中引用父类的成员
- 多层页面的跳转
- 【急求】android源码编译时如何用指定文件覆盖已有文件
- 再起风云:关于java异常处理try, catch的疑惑....小弟刚从汇编,c/c++转过android
- eclipse配置安卓出现这个错误
- 求解百度map的Mapview.getmap()返回空指针异常问题
- 关于cursor
- 关于google map的一点问题
private Handler mHandler = new Handler();
private Runnable testRunnable = new Runnable(){ int mInt = 10;
public void run(){
while(mInt < 21){
showProcess(mInt);
invalidate();
mHandler.postDelay(testRunnable, 100);
}
}
while (_isRunning())
{
Canvas c = null;
try {
c = _surfaceHolder.lockCanvas(null);
synchronized (_surfaceHolder) { //myPaint(c);
mHandler.post(testRunnable); }
} catch(Throwable e) {
exceptionCaught(e,EXCEPTION_RUN);
} finally { if (c != null) {
_surfaceHolder.unlockCanvasAndPost(c);
}
}
}}
写错了有个地方, private Runnable testRunnable = new Runnable(){ int mInt = 10;
public void run(){
if(mInt < 21){
showProcess(mInt);
invalidate();
mInt += 10;
mHandler.postDelay(testRunnable, 100);
}
}
有空再去看看那个例子~~~~
发现 只用handler 就可以了
可以不用Runnable
postDelayed(runnable , delayMillis)
sendMessageDelayed(msg, delayMillis)如果调用postDelayed 那就需要 Runnable
如果调用sendMessageDelayed 就不需要 Runnable
因为一旦有多个物体要运动的话 只用handler 会很卡。。