평범한 개발자 행복한 가족, 패밀리그램

개발/안드로이드

ScrollView안에 RecyclerView를 넣었을 때 RecyclerView의 Scrolling 무시하기.

패밀리그램 2016. 12. 13. 08:56

NestedScrollView 내에 RecyclerView를 넣어 좀 더 다양한 UI를 구현하려고 할 때 NestedScrollView와 RecyclerView의 Scrolling 방향이 동일 할 경우 발생하는 문제가 있다.

뭐 당연한 문제지만, 두개의 View 모두 Vertical scrolling이라고 할 때 ScrollView 영역에서는 스크롤이 자연스럽지만, RecyclerView에서는 부 자연스러운 동작을 보여준다.


그리고 SupportToolBar의 layoutScrollingFlag가 아래와 같을 때  RecyclerView영역에서는 정상동작 하지 않는 모습을 보여준다.


1
    app:layout_scrollFlags="scroll|enterAlways"
cs


이런 경우 RecyclerView의 Scrolling을 막아야하는데 RecyclerView에 사용되는 LayoutManager를 커스텀하여 Scrolling을 막을 수 있다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
    private static final class CustomLinearLayoutManager extends LinearLayoutManager{
 
        private boolean isEnabledVerticalScrolling = false;
 
        public CustomLinearLayoutManager(Context context) {
            super(context);
        }
 
        public CustomLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
            super(context, orientation, reverseLayout);
        }
 
        public CustomLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
            super(context, attrs, defStyleAttr, defStyleRes);
        }
 
        public void setEnabledVerticalScrolling(boolean b){
            isEnabledVerticalScrolling = b;
        }
 
        @Override
        public boolean canScrollVertically() {
            return isEnabledVerticalScrolling && super.canScrollVertically();
        }
    }
cs



반응형