0
我寫了下面的簡單代碼來查看渲染的行爲。在這段代碼中,我正在改變屏幕的顏色。瞭解Canvas.onDraw()的概念問題?
我無法理解的是,爲什麼這段代碼永遠運行?我沒有使用無限循環,但此代碼將永遠運行!
請告訴我原因。謝謝
package kamalan.com.androidbasicstarter;
import java.util.Random;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
public class RenderViewTest extends Activity{
class RenderView extends View{
Random rand = new Random();
public RenderView(Context context) {
super(context);
}
protected void onDraw(Canvas canvas){
canvas.drawRGB(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
invalidate();
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(new RenderView(this));
}
}