0
오버레이를 그려 상자에있는 상자와 텍스트를 표시하지만 표시되지 않는 것 같습니다.Android 사용자 정의 오버레이되지 않음
오버레이 클래스는 전혀 그리기 방법에 들어간 적이
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);
}
는
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);
}
}
MyLocationOverlay의 다른 오버레이는 사용자가 이전 점을 나타내고 다른 오버레이뿐만 아니라 잘 작동 디스플레이 오버레이 클래스 값을 전달하는 방법 centerOnLocation(Location loc)
전화입니다 . 도움
이 정말에만 @Override 부분이 필요합니다. –
예, 오버레이 클래스를 확장하고 그리기 기능을 사용자 정의 코드로 대체하려고합니다. 행운을 빌어 요 –
감사합니다. 재정의가 누락되었음을 눈치 채지 못했습니다. –