如何在MapView上创建动态编号的Pin指针?

Har*_*had 5 android google-maps android-mapview

我想在我的上面显示一些位置MapView.这些位置将显示将具有数字1,2,3等的引脚(类似于Google地图结果,但它是A,B,C ..).我认为拥有所有数字的引脚是不可行的.

有没有办法,我可以创建一个带有引脚背景的布局,TextView我将动态地将数字放入,TextView并且该布局用作可绘制引脚?

或者任何其他方法来实现这一目标?请提供一些建议.

(我能够显示不同的可绘制引脚.MapView我只想动态创建drawable)

Har*_*had 5

解决了这个问题.

使用引脚背景使TextView膨胀,并将位置动态设置为TextView.

public Drawable createFromView(int positionNumber)
{
    LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View view = inflater.inflate(R.drawable.pin_icon, null, false);
    TextView tv = (TextView) view.findViewById(R.id.pin_background);
    tv.setText("     "+ (positionNumber+1) );   // +1 since position is starting from 0
    tv.setDrawingCacheEnabled(true);
    tv.layout(0, 0, 50, 50);
    tv.buildDrawingCache();
    Bitmap b = Bitmap.createBitmap(tv.getDrawingCache());
    tv.setDrawingCacheEnabled(false);
    Drawable d = new BitmapDrawable(b);
    return d;
}
Run Code Online (Sandbox Code Playgroud)