PopupMenu click causing RecyclerView to scroll

后端 未结 4 1623
温柔的废话
温柔的废话 2021-02-19 16:33

I have an overflow button inside a CardView in Recyclerview. Whenever I am clicking the button,I show a popup menu but also RecyclerView i

4条回答
  •  后悔当初
    2021-02-19 17:31

    You can have your AnchorView override requestRectangleOnScreen() and return false. This will prevent any parent ScrollView from scrolling.

    So, in your case, imgBtnOverflow would be a custom ImageButton, like so:

    /**
     * A custom {@link ImageButton} which prevents parent ScrollView scrolling when used as the
     * anchor for a {@link android.support.v7.widget.PopupMenu}
     */
    public class NonScrollImageButton extends ImageButton {
    
        public NonScrollImageButton(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        @Override
        public boolean requestRectangleOnScreen(Rect rectangle, boolean immediate) {
            return false;
        }
    }
    

    Props to jankovd (https://gist.github.com/jankovd/19ef35efd1f00e9213fa)

    An issue has been filed against the Support PopupMenu here: https://code.google.com/p/android/issues/detail?id=135439

提交回复
热议问题