2011-06-28 21 views
5

Quiero mostrar algunas ubicaciones en mi MapView. Estas ubicaciones mostrarán los pines que tendrán números 1,2,3 .. etc. (similar al resultado de los mapas de Google, pero son A, B, C ..). Creo que no es factible tener alfileres de todos los números.¿Cómo crear punteros de pin numerados dinámicamente en MapView?

¿Hay alguna manera de que pueda simplemente crear un diseño con el fondo del pin con TextView y coloque el número de forma dinámica en TextView y que el diseño no se use como pin dibujable?

O cualquier otro método para lograr esto ?? Por favor, brinde algunas sugerencias.

(soy capaz de mostrar diferentes pines dibujable en MapView .I sólo quieren crear dinámicamente dibujables)

Respuesta

5

Resuelto esto.

infla el TextView con el fondo PIN y establecer dinámicamente la posición en 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; 
} 
+0

Esto es realmente genial, justo lo que he estado buscando. ¿Por casualidad también tiene un fragmento de código para el archivo xml de diseño? – kfox

+0

@kfox para R.drawable.pin_icon. No es más que un diseño lineal que contiene un fondo TextView.Linear Layout es tu pin. Simplemente alinee TextView en el centro. Avíseme si aún lo necesita. Se lo proporcionaré. – Harshad

+0

Si R.drawable.pin_icon es un diseño lineal con una vista de texto. ¿Eso quiere decir que R.id.pin_background es un diseño lineal que contiene la imagen pin? –