开发者

How to Create Dynamically numbered Pin Pointers on MapView?

开发者 https://www.devze.com 2023-03-16 06:10 出处:网络
I want to display some locations on my MapView. These locations will show pins which will have numbers 1,2,3.. so on(Similar to Google maps result but it is A,B,C..). I think it is not feasible to hav

I want to display some locations on my MapView. These locations will show pins which will have numbers 1,2,3.. so on(Similar to Google maps result but it is A,B,C..). I think it is not feasible to have pins of all numbers.

Is there any way that i can just create a layout with pin background with TextView and I will dynamically put number in TextView and that layout ill use as drawable pin??

Or any other me开发者_运维百科thod to achieve this?? Please provide some suggestions.

(I am able to show different drawable pins on MapView.I just want to create drawables dynamically)


Solved this.

Inflated the TextView with pin background and dynamically set the position into 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

精彩评论

暂无评论...
验证码 换一张
取 消