0
オーバーレイを描画しようとしていますが、そのボックス内にボックスとテキストが表示されますが、表示されないようです。Androidカスタムオーバーレイが描画されない
オーバーレイクラスは、それがすべてでdrawメソッドに入ったことはありません
public class StatsOverlay extends Overlay
{
Paint paint;
double altitude;
float speed;
float distance;
float maxSpeed;
long time;
double calories;
boolean showStats;
public StatsOverlay()
{
}
public void draw(Canvas canvas, MapView mapView, Paint paint, boolean shadow)
{
super.draw(canvas, mapView, shadow);
if(showStats == true)
{
paint = new Paint();
paint.setAntiAlias(true);
paint.setARGB(80, 245, 245, 245);
canvas.drawRect(0, 0, 350, 100, paint);
paint.setTextSize(15);
paint.setARGB(280, 0, 0, 0);
canvas.drawText("Time: "+(time/60)+":"+(time%60)+" Calories: "+calories+" Distance: "+distance+"KM\n"+"Speed: "+speed+"KM/H Max Speed: "+maxSpeed+"KM/H", 8, 14, paint);
}
}
public void setStats(long time, float distance, float speed, float maxSpeed, double calories)
{
this.time = time/1000;
this.distance = distance;
this.speed = speed;
this.maxSpeed = maxSpeed;
this.calories = calories;
}
}
下に表示されます。
これは、オーバーレイを呼び出すコードのスニペットです。 onLocationChange(Location loc)
方法において
public class Begin_Run_Map extends MapActivity implements LocationListener
{
//Other variables declared here for calculations
//Overlay variables
MyLocationOverlay myLocOver;
StatsOverlay statsOverlay;
public void onCreate(Bundle savedStateInstance)
{
super.onCreate(savedStateInstance);
setContentView(R.layout.race_run);
//Setting up of the mapview, initalising variables and setting up of location manager etc done here
mapView = (MapView) findViewById(R.id.race);
mapView.setSatellite(false);
mapView.setBuiltInZoomControls(true);
mapView.displayZoomControls(true);
mapCon = mapView.getController();
screenOverlays = mapView.getOverlays();
myLocOver = new MyLocationOverlay(this,mapView);
statsOverlay = new StatsOverlay();
screenOverlays.add(statsOverlay);
screenOverlays.add(myLocOver);
}
MyLocationOverlayの他のオーバーレイが正常に動作し、ならびにユーザーに以前のポイントを示す別のオーバーレイディスプレイオーバーレイクラスに値を渡す方法centerOnLocation(Location loc)
private void centerOnLocation(Location loc)
{
// TODO Auto-generated method stub
double lat = loc.getLatitude();
double lng = loc.getLongitude();
GeoPoint me = new GeoPoint((int) (lat * 1E6),(int) (lng * 1E6));
mapCon.animateTo(me);
if(statsOverlay != null)
{
statsOverlay.setStats(times.get(times.size()-1), distance, avg_Speed, maxSpeed, caloriesBurned);
}
}
を呼び出すあります。ヘルプ
それは本当にだけ@Override一部を必要としています。 –
はい、オーバーレイクラスを拡張していて、その描画関数をカスタムコードに上書きしたいからです。幸運 –
ありがとうございます。 –