Scale Bar
This example demonstrates how to create a scale bar using XML with the Mapbox Maps SDK for Android.
The code below sets adds a scale bar to the activity layout to show how many miles a segment of the map covers. This XML element renders the R.layout.activity_scale_bar
visual which shifts in scale as you zoom in and out of the map.
Android Examples App Available
This example code is part of the Maps SDK for Android Examples App, a working Android project available on GitHub. Android developers are encouraged to run the examples app locally to interact with this example in an emulator and explore other features of the Maps SDK.
See our Run the Maps SDK for Android Examples App tutorial for step-by-step instructions.
package com.mapbox.maps.testapp.examples
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.mapbox.maps.testapp.R
/**
* Activity to showcase scale bar custom configuration using xml attributes.
*/
class ScaleBarActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_scale_bar)
}
}
Was this example helpful?