【发布时间】:2012-09-01 22:34:41
【问题描述】:
我读了 Hello Android 书,但我不明白代码的某些部分。
public class PuzzleView extends View {
private static final String TAG = "Sudoku" ;
private final Game game;
public PuzzleView(Context context) {
super(context);
this.game = (Game) context;
setFocusable(true);
setFocusableInTouchMode(true);
}
// ...
}
private float width; // width of one tile
private float height; // height of one tile
private int selX; // X index of selection
private int selY; // Y index of selection
private final Rect selRect = new Rect();
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
width = w / 9f;
height = h / 9f;
getRect(selX, selY, selRect);
Log.d(TAG, "onSizeChanged: width " + width + ", height "+ height);
super.onSizeChanged(w, h, oldw, oldh);
}
超级(上下文);在这段代码中,它的含义和作用是什么?
this.game = (游戏) 上下文;为什么我们写这个?它有什么作用?
Android 网站说 onSizeChanged() 函数用于: “当这个视图的大小发生变化时,这在布局期间被调用” 这意味着如果要旋转手机,这个函数会使程序的视图显示为真。这是真的吗?
getRect(selX,selY,selRect);它是什么意思,有什么作用?
请帮助我。 干杯。
【问题讨论】:
标签: java android superclass