我在地图上显示特定项目时遇到困难。当用户单击一个点时,我想放置一个顶部带有计数器的对象。我正在考虑使用文本视图并将其转换为可绘制对象,使用此方法,但它不起作用。我尝试的看起来像这样:
.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout ... >
<TextView
android:id="@+id/object"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableBottom="@drawable/car"
android:text="Human 1,2..." /> <!-- Here should be the counter modified programatically -->
</LinearLayout>
法典:
public boolean onTouchEvent(MotionEvent e, MapView m) {
....
CustomPinPoint custom = new CustomPinPoint(getHuman(), Main.this);
}
private Drawable getHuman() {
Bitmap snapshot = null;
Drawable drawable = null;
LayoutInflater li = Main.this.getLayoutInflater();
View view = li.inflate(R.layout.human, null); //human is the layout
view.setDrawingCacheEnabled(true);
view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW);
try {
snapshot = Bitmap
.createBitmap(view.getDrawingCache());
drawable = new BitmapDrawable(snapshot);
} finally {
view.setDrawingCacheEnabled(false);
}
return drawable;
}
目前,我在Bitmap.createBitmap(view.getDrawingCache());
处得到空指针。用尺寸尝试过,仍然没有成功。有人可以告诉我我做错了什么吗?或者是否有另一种方法可以从文本视图中获取可绘制对象?
提前谢谢,科斯明。
你的问题不是很清楚...
如果您想始终将对象放置在同一个位置,并且希望独立于用户触摸地图的位置显示它,请将 oject 添加到具有地图视图的相同布局中,如我在此答案中显示的动画菜单按钮在 MapView 顶部,然后使其可见/不可见并根据需要更改计数器。
如果您想要其他东西,请在您的问题中添加更多信息。
祝你好运。