Android Wear: Scrollable (curved) activities with BoxInsetLayout behaviour

While creating a  watch face for my Android Wear watch,  I implemented a configuration activity with some options . Some them needed a simple confirmation by the user to explain them the implications and get the okay to activate.

BoxInsetLayout for fullscreen activities


As a first approach I created a new activity based on the android.support.wear.widget.BoxInsetLayout. It contained a desciption, question and two buttons within a FrameLayout.  Everything was fine and the activity worked well.

<android.support.wear.widget.BoxInsetLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:boxedEdges="all">

[..]

</LinearLayout>

</android.support.wear.widget.BoxInsetLayout>


You can find the complete layout xml file here: https://bitbucket.org/snippets/devdev-dev/KexnM6 

Problem: BoxInsetLayout is not able to scroll


With further development I wanted to reuse the confirmation activity but while testing I mentioned a problem with the BoxInsetLayout: It does not support content higher than the screen - there is no scrolling.

Inner scroll

Fullscreen only

Surrounding a ScrollView with a BoxInsetLayout did work but the scrollbars where in the middle of the screen and the content gets cut off at the top of the screen. Another option was to use the WearableRecyclerView instead of a BoxInsetLayout. But I did not wanted to misuse a list as wrapper.

I tried many different ways to get the BoxInsetLayout scrollable but did not get happy with any of the results. Even asking a question on Stackoverflow did not help me any further.

Solution: Scrapping the BoxInsetLayout


Perfect

As mentioned on different sites in the internet Android Wear 2.0+ comes with a default support for curved scrollbars when using Scroll Views on round screens. I removed the BoxInsetLayout to get the activity scrollable (with curved scrollbars).

One problem: The text is cut-off on round screens as the inset is missing. I simple calculated them by myself and added a padding to my LinearLayout within the ScrollView and that is it. Everything is working as intended now and until now there a no disadvantage from manually calculating the inset.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:id="@+id/layout_content"
android:layout_width="match_parent"
android:layout_height="wrap_content">
[..]
</LinearLayout>

</ScrollView>

 

class ConfirmationActivity : Activity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
[..]
adjustInset()
}

private fun adjustInset() {
if (applicationContext.resources.configuration.isScreenRound) {
val inset = (FACTOR * Resources.getSystem().displayMetrics.widthPixels).toInt()
layout_content.setPadding(inset, inset, inset, inset)
}
}

companion object {
private const val FACTOR = 0.146467f // c = a * sqrt(2)
}
}


You can find the xml layout and kotlin class file here: https://bitbucket.org/snippets/devdev-dev/keR67A