Use RecyclerView inside ScrollView with flexible Recycler item height

后端 未结 8 1659
误落风尘
误落风尘 2020-11-29 04:57

I want to know if there is any possible way to use RecyclerView?

Before this, I used RecyclerView with fixed height inside a

8条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-29 05:23

    I fully agree with Ashkan solution, big thanks (voted +1!), but there is one thing...

    If RecyclerView does scroll correctly inside ScrollView/NestedScrollView BUT it doesn't fling (intercept it) then the solution is to extend RecyclerView and override OnInterceptTouchEvent and OnTouchEvent. If you don't need any click actions but just want to present items with working fling then simply return false in both like below:

    public class InterceptingRecyclerView extends RecyclerView {
    
        public InterceptingRecyclerView(Context context) {
            super(context);
        }
    
        public InterceptingRecyclerView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        public InterceptingRecyclerView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
        }
    
        @Override
        public boolean onInterceptTouchEvent(MotionEvent e) {
            return false;
        }
    
        @Override
        public boolean onTouchEvent(MotionEvent e) {
            return false;
        }
    }
    

    Or actually it should be called NonIntercepting... ;) Simple as that.

提交回复
热议问题