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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | public abstract class HidingScrollListener extends RecyclerView.OnScrollListener { private static final int HIDE_THRESHOLD = 20; private int scrolledDistance = 0; private boolean controlsVisible = true; @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); if (scrolledDistance > HIDE_THRESHOLD && controlsVisible) { onHide(); controlsVisible = false; scrolledDistance = 0; } else if (scrolledDistance < -HIDE_THRESHOLD && !controlsVisible) { onShow(); controlsVisible = true; scrolledDistance = 0; } if ((controlsVisible && dy > 0) || (!controlsVisible && dy < 0)) { scrolledDistance += dy; } } public abstract void onHide(); public abstract void onShow(); } /*스크롤 방향 감지 하여 툴바 히든 처리 할때 사용*/ recycler_view.setOnScrollListener(new HidingScrollListener() { @Override public void onHide() { Dlog.d("onHide"); } @Override public void onShow() { Dlog.d("onShow"); } }); /*하단 감지*/ recycler_view.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) { super.onScrollStateChanged(recyclerView, newState); if (!recyclerView.canScrollVertically(1) && newState == RecyclerView.SCROLL_STATE_IDLE) { Dlog.d("bottom"); } } }); | cs |
'Android' 카테고리의 다른 글
| NestedScrollView 하단감지.. (0) | 2023.01.31 |
|---|---|
| 3자리 콤마, HTML태그 제거 (0) | 2022.11.30 |
| URL LINK 크롤링하는 메소드 (1) | 2022.09.19 |
| ButterKnife EditText Search actionId (0) | 2022.07.13 |
| AsyncTask Deprecated 대응 Rxjava (0) | 2022.04.06 |