Aditya's Blog

Mapbox Android: How to set padding in Location Layer plugin

LocationLayer plugin allows changing most of style defining custom styles in res but for padding we have to use LocationLayerOptions to set padding.
Here’s an example to set padding on top, to shift camera a bit below.

LocationLayerOptions options = locationLayerPlugin
                    .getLocationLayerOptions() // Get current options
                    .toBuilder() // Convert to LocationLayerOptions.Builder
                    .padding(new int[]{0, 800, 0, 0}) // Change padding (Left, Top, Right, Bottom)
                    .build(); // Build back with new padding
                    
locationLayerPlugin.applyStyle(options); //Set new options

It took me a while to figure this, hope this will be helpful for someone. Let me know if you know any better implementation in comments below.