Android:我可以从视图的onDraw方法调用Log.i方法吗?

时间:2012-09-20 19:21:20

标签: android ondraw

我正在尝试调用Log.i方法来测试View的刷新率:

public class GameView extends View {

public GameView(Context context) {
    super(context);
    }

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    canvas.drawColor(Color.WHITE);
    Log.i("OnDraw","ping");
    invalidate();
    }

为什么这不起作用?

public class GameUI extends Activity implements OnClickListener, OnTouchListener {
/** Called when the activity is first created. */

GameView gameview;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    gameview = new GameView(this);
    setContentView(gameview);
}

1 个答案:

答案 0 :(得分:1)

试试这个

public GameView(Context context)
{
    super(context);
    this.setWillNotDraw(false);
}

这可能对你有帮助..........