0
私はカスタムビューを持っています。アンドロイドコールはいつ呼びますか? onMeasureとonLayoutを呼び出した後は?アンドロイド:カスタムビューの実装
'package global.domination.pack;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.util.Log;
import android.view.View;
public class TileView extends View {
// rules about what can be and is on this tile
boolean bLand;
boolean bSea;
boolean bAir;
boolean bOccupied;
Character _character;
// this tile's coordinates
int nX;
int nY;
// bitmaps used for drawing this tile
Bitmap _originalBitmap;
Bitmap _finalBitmap;
// this constructor initializes all variables (creates the tile)
public TileView(Context context, boolean isLand, boolean isSea, boolean isAir, boolean isOccupied, int x_Coordinate, int y_Coordinate, Bitmap bitmap) {
super(context);
//Initialize variables and set tile graphic.
bLand = isLand;
bSea = isSea;
bAir = isAir;
bOccupied = isOccupied;
nX = x_Coordinate;
nY = y_Coordinate;
_originalBitmap = bitmap;
_character = null;
_finalBitmap = bitmap;
}
/* This method is called by parent view when it
* wants to know this view's drawing preferences
*/
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// set this tiles dimensions
this.setMeasuredDimension(50, 50);
}
/* This method is called by parent view when it wants
* this view to draw itself.
*/
@Override
protected void onDraw(Canvas canvas) {
// attempt to draw the _finalBitmap (tile graphic with character graphic)
try{
canvas.drawBitmap(_finalBitmap, 0, 0, null);
}
catch(RuntimeException rtException){
Log.e("EXCEPTION", "ERROR DRAWING FINAL BITMAP" + rtException.getMessage() , rtException);
}
}
}
'
もっと分かりやすいようにコードスニペットを追加してください。 – srinathhs