public class Background extends RelativeLayout{ private Def.Status eStatus;
private Bitmap bmpSky;
public Background(Context context, Def.Map style ) {
super(context);
int res = GetBackRes( style );
bmpSky = BitmapFactory.decodeResource( this.getResources(), res );
eStatus = Def.Status.STATUS_STOPPED;
} public void Draw( int offset ){
if( Def.Status.STATUS_STARTED != eStatus )
return;
Tools.ShowLog( "Background Draw(int offset) " );
this.postInvalidate();
} public void Start() {
if( Def.Status.STATUS_STOPPED != eStatus )
return;
eStatus = Def.Status.STATUS_STARTED;
} public void Stop() {
this.removeAllViews();
eStatus = Def.Status.STATUS_STOPPED;
}
//-------------------
// get background res id
private int GetBackRes( Def.Map style ) {
int ret = R.drawable.road_city_sky;
switch( style ){
case MAP_CITY: ret = R.drawable.road_city_sky; break;
case MAP_NIGHT: ret = R.drawable.road_night_sky; break;
case MAP_GRASS: ret = R.drawable.road_grass_sky; break;
case MAP_DUSK: ret = R.drawable.road_dusk_sky; break;
case MAP_SNOW: ret = R.drawable.road_snow_sky; break;
case MAP_DESERT:ret = R.drawable.road_desert_sky; break;
default: ret = R.drawable.road_city_sky; break;
}
return ret;
}
//@Override
protected void onDraw( Canvas canvas ){
Tools.ShowLog( "onDraw(Canvas canvas)" );
super.onDraw(canvas);
com.minstron.android.tools.Rect rc = new com.minstron.android.tools.Rect( Def.race_back_sky );
Tools.ConvertRect(rc);
canvas.drawBitmap(
bmpSky,
new Rect( 0, 0, bmpSky.getWidth(), bmpSky.getHeight() ),
new Rect( 0, 0, (int)rc.GetWidth(), (int)rc.GetHeight() ),
null);
}
}Activity->RelativeLayout->中
if( null == oBackground )
oBackground = new Background( oRoot, oSim.GetCurrentMap() );
this.addView(oBackground);
Tools.SetViewRect(oBackground, Def.race_back_sky);
oBackground.Start();
外面有个Timer按帧调用 Draw( int offset ), (可以进入)
但是为什么总是进不了 onDraw(Canvas canvas)(无法进入)
在Draw( int offset )中...
this.postInvalidate();
已经在Draw( int offset )中被调用了......
RelativeLayour 可以的 我有另外的8个控件 都是这么用的.
但是不知道怎么就这个就不行了.
我看它里面有个长度12的数组,但是我只用了9个啊.
问又问不出个所以.
放弃ANDROID吧.