使用带有图形页面自定义绘制图纸怪假象 [英] Strange drawing artefact using custom drawable with MapView
问题描述
我想添加自己绘制并在一个图形页面的一系列叠加使用。可提拉基本上是一个圆形的盒子具有黑色轮廓和在中间的一个数字。
I'm trying to add my own drawable and use it in a series of overlays on a MapView. The drawable is basically a rounded box with a black outline and a number in the middle.
我已成功地做到这一点使用下面的code,但是有什么样子的一个标志,我的框的左侧,我当然不认为我画 - 所以我不知道它是什么可。
I have managed to achieve this using the code below, however there is what looks like a flag to the left of my box, which I certainly don't think I have drawn - so I'm wondering what it can be.
这是形象的例子:
This is an example of the image:
编辑 - 这是一个是否绘制圆会发生什么:
Edit - this is what happens if a circle is drawn:
我的code是如下:
自定义绘制对象:
public class BikeDrawable extends Drawable {
int colour;
String bikes;
public BikeDrawable (int bikes){
this.bikes = Integer.toString(bikes);
if (bikes < 4) {
colour = Color.RED;
}
else if (bikes > 3 && bikes < 9){
colour = Color.argb(244, 255, 127, 42);
}
else {
colour = Color.GREEN;
}
}
@Override
public void draw(Canvas canvas) {
Paint rectanglePaint = new Paint();
rectanglePaint.setColor(colour);
rectanglePaint.setStyle(Style.FILL);
RectF rectangle = new RectF(0.0f, 0.0f, 20.0f, 20.0f);
Paint strokepaint = new Paint();
strokepaint.setStyle(Paint.Style.STROKE);
strokepaint.setStrokeWidth(2);
strokepaint.setARGB(255, 0, 0, 0);
canvas.drawRoundRect(rectangle, 4.0f, 4.0f, rectanglePaint);
canvas.drawRoundRect(rectangle, 4.0f, 4.0f, strokepaint);
Paint textpaint = new Paint();
textpaint.setARGB(255, 0, 0, 0);
textpaint.setTextAlign(Paint.Align.CENTER);
canvas.drawText(bikes, 10, 14, textpaint);
}
@Override
public int getOpacity() {
return 0;
}
@Override
public void setAlpha(int alpha) {
}
@Override
public void setColorFilter(ColorFilter cf) {
}
}
使用的图形页面:
bikeOverlay = new PointsOverlay(start_icon);
BikeDrawable start_1_drawable = new BikeDrawable (start_1.capacity);
OverlayItem start_1_overlayitem = new OverlayItem(new GeoPoint(start_1.lat,start_1.lon), null, null);
start_1_overlayitem.setMarker(start_1_drawable);
mapOverlays.add(bikeOverlay);
bikeOverlay.addOverlay(start_1_overlayitem);
有没有人有任何想法是怎么回事?它是从OverlayItem造成的假象?
Does anyone have any idea what is going on here? Is it an artefact from OverlayItem?
推荐答案
这是通过覆盖PointsOverlay的draw()方法如下实现:
This was achieved by overriding the draw() method of the PointsOverlay as follows:
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow)
{
if(!shadow)
{
super.draw(canvas, mapView, false);
}
}
由于etteyafed - 我会认为你不点,如果你回答了,但我想关闭这个功能。
Thanks to etteyafed - I would have credited you with the points if you had answered, but I wanted to close this off.
这篇关于使用带有图形页面自定义绘制图纸怪假象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!