androidscrollandroid-recyclerviewwear-os

WearableListView Header


I am trying to create a WearableListView similar to the one in the default Settings app. I have a WearableListView that scrolls, and animates each element. All I need now is a header on top of the list that scrolls up when the list scrolls. This is the same behavior that the title 'Settings' has in the Settings app.

The only method I have found to do this, used here: How to Set the Layout for topEmptyRegion, implements a WearableListView.OnScrollListener(). Then uses the onAbsoluteScrollChange() method to set the displacement of the TextView used as a header. But, according to the Android Developer References, this method is deprecated. The documentation even states: BE ADVISED DO NOT USE THIS This might provide wrong values when the contents of a RecyclerView change.

I would like to know if anyone else has found a way to implement a header that behaves this way, one that is not deprecated. Possibly something that I missed in the Android Wear documentation?

EDIT:

I tried to implement this method anyway. As it turns out, WearableListView.setOnScrollListener() would not take a new WearableListView.OnScrollListener(). Instead it asked for its parent RecyclerView.OnScrollListener, which does not have a onAbsoluteScrollChange() method. It does have an onScrolled() method, which I tried to implement. As it turns out, this completely overrides the default scroll listener for WearableListView and makes it so the centered item can be off-center. Definitely not the effect I was looking for.


Solution

  • Since onScroll() is not deprecated, you may be able to accomplish the same by implementing that in your listener:

    @Override
    public void onScroll(int scroll) {
        header.setY(header.getY() - scroll);
    }
    

    where header is the header component.

    EDIT: Make sure you use WearableListView.addOnScrollListener not WearableListView.setOnScrollListener()