Talkback focus goes to toolbar items when recyclerview within nestedscrollview is scrolled

微笑、不失礼 提交于 2021-01-27 05:25:56

问题


I have a nestedscrollview within my layout which contains few texts, buttons and recyclerviews.

When talkback is on, I am able to traverse through all elements. But I face an issue. When my horizontal recyclerview is scrolled and then I swipe to hear the talkback, the focus moves to the toolbar first item. Then I need to traverse through all the visible items to reach to the horizontal scrollview scrolled item.

This issue arises only for recyclerviews within nestedscrollview.

My nestedscrollview in layout is added in this manner:

<androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        //my contents

</androidx.core.widget.NestedScrollView>

My recyclerview in layout is added in this manner:

<LinearLayout
     android:id="@+id/photosLL"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:orientation="vertical">

     <androidx.recyclerview.widget.RecyclerView
          android:id="@+id/photosRV"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          tools:listitem="@layout/list_item_photo" />
</LinearLayout>

Is this expected behaviour or if its an issue, how to solve the same?


回答1:


Here is a quote from the first link I offered at the end, which I think is relevant to your problem:

"In touch mode, there is no focus and no selection. Any selected item in a list of in a grid becomes unselected as soon as the user enters touch mode. Similarly, any focused widgets become unfocused when the user enters touch mode."

I think what you need is to set these attributes on your recyclerView:

 android:focusableInTouchMode="true"
 android:descendantFocusability="beforeDescendants"

If you are looking for more information, read:

Difference between focusable and focusableInTouchMode

and

explain descendantFocusability = afterDescendants



来源:https://stackoverflow.com/questions/61590920/talkback-focus-goes-to-toolbar-items-when-recyclerview-within-nestedscrollview-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!