MobileAppDeveloper
MobileAppDeveloper

Reputation: 1049

Adding a custom view to the mapview that does not move with the map view

I want to add a view on top of mapview that does not move when I move the map view. The mapview can be zoomed in or zoomed out but the view should be stationary at the center of the map view. Please guide me how to do it.

Thanks

Upvotes: 0

Views: 240

Answers (1)

Amir_P
Amir_P

Reputation: 9019

This should be your xml code

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.google.android.gms.maps.MapView
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    </RelativeLayout>

Then in your Activity do this

RelativeLayout.LayoutParams layoutParams = new
    RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
relativeLayout.addView(yourView, layoutParams);

Upvotes: 2

Related Questions