Search code examples
android-studioosmdroid

How to add ButtonOverlay on a Map(osmdroid)


I want to add a button overlay but it shouldn't be based on the geopoint but instead based on the screen. So whenever i scroll the map, the button should still exists and will remain in that position, How do i do that?


Solution

  • Just add it to your android layout for the activity/fragment

    Example here: https://github.com/osmdroid/osmdroid/blob/master/OpenStreetMapViewer/src/main/res/layout/sample_cachemgr.xml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/parent_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <org.osmdroid.views.MapView
            android:id="@+id/mapview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tilesource="Mapnik" />
    
        <Button android:id="@+id/btnCache"
            android:layout_width="fill_parent"
            android:text="Cache Manager"
            android:layout_height="wrap_content"></Button>
    
    </RelativeLayout>