Wearable RecyclerView

Promise Ochornma
2 min readJul 15, 2020

--

The Wearable UI Library includes the WearableRecyclerView class, which is a RecyclerView implementation for creating lists optimized for wearable devices. You can use this interface in your wearable app by creating a new WearableRecyclerView container.

Wearable RecyclerView

Wearable recyclerview is used to create a circular layout and is an alternative to Boxlayout on Circular WearOS.

The most used public methods of this view are:

  1. setCircularScrollingGestureEnabled(boolean): For enabling/disabling circular touch scrolling for this view.
  2. setEdgeItemsCenteringEnabled(boolean): This method is used to indicate if the view should always align the first and last items with the vertical center of the screen.

Below I will give an example with the Home screen of DCLM Watch

Home Screen of DCLM Watch

First the layout file and then the list item, the Adapter and the Activity

If you need to implement custom child layout behavior on scroll, then you can use then you use this constructor WearableLinearLayoutManager(Context context, LayoutCallback layoutCallback)and then set your custom Layout Callback as the parameter for the layoutCallback. You can trust Android Magic by coping theirs as your custom LayoutCallback

/** How much should we scale the icon at most.  */
```private const val MAX_ICON_PROGRESS = 0.65f

class CustomScrollingLayoutCallback : WearableLinearLayoutManager.LayoutCallback() {

private var progressToCenter: Float = 0f

override fun onLayoutFinished(child: View, parent: RecyclerView) {
child.apply {
// Figure out % progress from top to bottom
val centerOffset = height.toFloat() / 2.0f / parent.height.toFloat()
val yRelativeToCenterOffset = y / parent.height + centerOffset

// Normalize for center
progressToCenter = Math.abs(0.5f - yRelativeToCenterOffset)
// Adjust to the maximum scale
progressToCenter = Math.min(progressToCenter, MAX_ICON_PROGRESS)

scaleX = 1 - progressToCenter
scaleY = 1 - progressToCenter
}
}
}```

--

--