Icon on top of another icon in Android

262 views Asked by At

I'm coding an android app (using java) maps-like and I use two kind of markers from Google Maps SKD: one for my current position, the other one indicates me places of intereset.

I set two different icons for these markers, how can I give to one of them the priority? I want mu current position icon marker to be shown over all other icon markers, how can I do that?

Thank you for time :)

EDIT: here's some code I'm using for my current position marker

        Drawable arrowDrawable = getResources().getDrawable(R.drawable.current_position_icon);
        BitmapDescriptor arrowIcon = getMarkerIconFromDrawable(arrowDrawable);

        Marker currentPositionMarker = gMap.addMarker(new MarkerOptions()
                .position(new LatLng(location.getLatitude(), location.getLongitude()))
                .draggable(false)
                .rotation(location.getBearing())
                .icon(arrowIcon)
                .flat(true));

And here's some code I'm using to set my other markers

    Marker marker = gMap.addMarker(new MarkerOptions()
            .position(new LatLng(event.getLatitude(), event.getLongitude()))
            .title("Acc. value -> " + Double.toString(event.getAccelerometerValue()))
            .icon(potholeIcon)
            .draggable(false));

It's the only time where I use my markers, I don't use it im my XML or in other Java code.

1

There are 1 answers

4
JumperBot_ On

Render your "current position icon" after you rendered every other icon.

If it's XML then just add it last.

If it's in Java then just declare and add it to the layout last.

Can't provide code if you can't provide code though...

Edit:

Made out my mind, I'll provide some code.

XML:

    <Layout...>
        <Other_Icon.../>
        <Other_Icon.../>
        <Other_Icon.../>
        <Your_Current_Position.../>
    </Layout...>

Or

Java:

    Layout layout=new Layout(...);
    //A lot of other icons...
    layout.addView(icon1);
    layout.addView(icon2);
    layout.addView(icon3);
    //Your position icon...
    layout.addView(your_current_position_icon);

Or, if you are using drag-and-drop.

Just drop the icon last.

(But it would be better if you code it instead just to make sure.)