0

I have standard layout using coordinatorLayout allow user to scroll up and down to see a page, and it expand or collapse based on the scroll position, and below the AppBarLayout I have view pagers allow user to swipe left and right.

enter image description here

I would like to support accessibility for all users, but android talkback does not seem to work well in coordinator layout.

When I have content that occupied the entire screen inside CollapsingToolbarLayout and the talkback only read thru all the elements on current screen and does not auto scroll down to hidden content. I had to use two fingers to scroll down so that the views become at least partial visible to the screen, then talkback will read the view.

Does anyone know how I can support auto scroll on AppBarLayout?

bj4947
  • 880
  • 11
  • 32

1 Answers1

0

So I somehow made it worked. But I still don't know why auto scroll in collapsing layout does not work when talkback turned on. Instead, I manually scroll for the user. There are few callback to listen for specific view. When the focus changed, I then just user animator to scroll the screen for user.

ViewCompat.setAccessibilityDelegate(
    YOUR_VIEW,
    object : AccessibilityDelegateCompat() {
        override fun onPopulateAccessibilityEvent(host: View?, event: AccessibilityEvent?) {
            if (event?.eventType == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED || event?.eventType == AccessibilityEvent.TYPE_VIEW_HOVER_ENTER) {
                val params = YOUR_VIEW.layoutParams as CoordinatorLayout.LayoutParams
                val behavior = params.behavior as AppBarLayout.Behavior

                ValueAnimator.ofInt().apply {
                    interpolator = DecelerateInterpolator()
                    addUpdateListener { animation ->
                        behavior.topAndBottomOffset = animation.animatedValue as Int
                        YOUR_VIEW.requestLayout()
                    }
                    //scroll up from current position and scroll 60% up.
                    setIntValues(behavior.topAndBottomOffset, (-totalRange * 6 / 10))
                    start()
                }
            }
            super.onPopulateAccessibilityEvent(host, event)
        }
    }
)
rekire
  • 47,260
  • 30
  • 167
  • 264
bj4947
  • 880
  • 11
  • 32