How to remove focus from RecyclerView inside ScrollView?

前端 未结 5 1375
傲寒
傲寒 2020-12-05 07:37

I have a Scrollview which contains an ImageView and RecyclerView. if navigation drawer opened then closed the RecyclerView auto scrolling to top, How to stop this?



        
5条回答
  •  Happy的楠姐
    2020-12-05 08:17

    That is because RecyclerView ALWAYS set:

    setFocusableInTouchMode(true);
    

    this is hard coded in its constructor.

    so if you apply those attribute in your XML for a RecyclerView

    android:focusable="false"
    android:focudeableInTouchMode="false"
    

    that would be useless, you end up with recycleView.isFocusable() == true...

    so the most elegant solution is to disable foucusable for RecyclerView's Parent.

    
        
    />
    

    or you can just simply setFocusable(false)

提交回复
热议问题