50. Tag 的命名慣例
public class MainActivity extends Activity {
private static final String TAG = MainActivity;
Log.println(Log.WARN, TAG, User account not exists.);
…
通常使?用該記錄存在的類別名稱(Class Name)
94. public class MyView extends View implements Runnable {
private Handler handler = new Handler();
private int x = 0;
private int y = 0;
private int offsetX = 5;
private int offsetY = 5;
public MyView(Context context) {
super(context);
this.setFocusable(false);
new Thread(this).start();
}
@Override
protected void onDraw(Canvas canvas) {
}
@Override
public void run() {
}
}
95. @Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.WHITE);
canvas.drawPaint(paint);
paint.setColor(Color.GREEN);
canvas.drawCircle(x+=offsetX, y+=offsetY, 20, paint);
if (x canvas.getWidth() || x 0) {
offsetX = -offsetX;
}
if (y canvas.getHeight() || y 0) {
offsetY = -offsetY;
}
}
96. @Override
public void run() {
while (true) {
handler.post(new Runnable() {
@Override
public void run() {
invalidate();
}
});
}
}