> For the complete documentation index, see [llms.txt](https://docs.mapbox.com/android/maps/llms.txt)

# Ornaments

![Update margins of ornaments when the map rotates.](https://docs.mapbox.com/android/assets/ideal-img/maps-examples-ornaments.e9b668c.480.png)

This example demonstrates how to validate margin displacement of ornaments when the map rotates using the **Mapbox Maps SDK for Android**.

The code below implements functionality to handle rotation gestures and updates to the margins of the logo, attribution, scale bar, and compass components presented on the map. When the map rotates, the margins of the ornaments are adjusted based on the map's bearing to keep their positions relative to the map view. The [`onRotate`](https://docs.mapbox.com/android/maps/api/latest/mapbox-maps-android/com.mapbox.maps.plugin.gestures/-on-rotate-listener/on-rotate.html) is utilized to track rotation gestures and calculate the necessary margin adjustments for the ornaments.

> **Note: Android Examples App Available**
> 
> This example code is part of the **Maps SDK for Android Examples App**, a working Android project [available on GitHub](https://github.com/mapbox/mapbox-maps-android/tree/v11.33.0/). 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](https://docs.mapbox.com/help/tutorials/maps-sdk-android-examples-app/) tutorial for step-by-step instructions.

**Kotlin**

Title: `OrnamentMarginActivity.kt`

[View on GitHub](https://github.com/mapbox/mapbox-maps-android/blob/v11.33.0/app/src/main/java/com/mapbox/maps/testapp/examples/OrnamentMarginActivity.kt)

```kt
package com.mapbox.maps.testapp.examples

import android.os.Bundle
import android.view.Gravity
import androidx.appcompat.app.AppCompatActivity
import com.mapbox.android.gestures.RotateGestureDetector
import com.mapbox.geojson.Point
import com.mapbox.maps.CameraOptions
import com.mapbox.maps.MapView
import com.mapbox.maps.plugin.attribution.attribution
import com.mapbox.maps.plugin.compass.compass
import com.mapbox.maps.plugin.gestures.OnRotateListener
import com.mapbox.maps.plugin.gestures.addOnRotateListener
import com.mapbox.maps.plugin.logo.logo
import com.mapbox.maps.plugin.scalebar.scalebar

/**
 * Test activity to validate correct margin displacement of ornaments when the map rotates.
 */
class OrnamentMarginActivity : AppCompatActivity(), OnRotateListener {

  private lateinit var mapView: MapView

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    mapView = MapView(this)
    setContentView(mapView)
    with(mapView.mapboxMap) {
      mapView.attribution.position = Gravity.END or Gravity.BOTTOM
      setCamera(
        CameraOptions.Builder()
          .center(Point.fromLngLat(23.760833, 61.498056))
          .zoom(14.0)
          .build()
      )
      addOnRotateListener(this@OrnamentMarginActivity)
    }
  }

  override fun onRotate(detector: RotateGestureDetector) {
    val bearing = mapView.mapboxMap.cameraState.bearing.toFloat()
    val margin = 2f * if (bearing <= 180f) bearing else 180f - (bearing % 180f)
    with(mapView.logo) {
      marginLeft = margin
      marginBottom = margin
      marginRight = margin
      marginTop = margin
    }
    with(mapView.attribution) {
      marginLeft = margin
      marginBottom = margin
      marginRight = margin
      marginTop = margin
    }
    with(mapView.scalebar) {
      marginLeft = margin
      marginBottom = margin
      marginRight = margin
      marginTop = margin
    }
    with(mapView.compass) {
      marginLeft = margin
      marginBottom = margin
      marginRight = margin
      marginTop = margin
    }
  }

  override fun onRotateEnd(detector: RotateGestureDetector) {
  }

  override fun onRotateBegin(detector: RotateGestureDetector) {
  }
}
```