본문 바로가기

나의 플랫폼/안드로이드

[Android] RecyclerView 에서 Scroll 정보 형태

336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
intcomputeHorizontalScrollExtent()

Compute the horizontal extent of the horizontal scrollbar's thumb within the horizontal range.

intcomputeHorizontalScrollOffset()

Compute the horizontal offset of the horizontal scrollbar's thumb within the horizontal range.

intcomputeHorizontalScrollRange()

Compute the horizontal range that the horizontal scrollbar represents.

intcomputeVerticalScrollExtent()

Compute the vertical extent of the vertical scrollbar's thumb within the vertical range.

intcomputeVerticalScrollOffset()

Compute the vertical offset of the vertical scrollbar's thumb within the vertical range.

intcomputeVerticalScrollRange()

Compute the vertical range that the vertical scrollbar represents.

출처 : https://developer.android.com/intl/ko/reference/android/support/v7/widget/RecyclerView.html


위 내용은 RecyclerView에 대한 Google Reference 이다.

이것만 보면 내용은 어느 정도 짐작이 가지만 정확한 값이 무엇인지 알기가 어려워서 테스트를 진행 했다.


테스트는 Vertical로만 진행 하였으며, Horizontal도 똑같은 값이 넘어 올거라고 생각 된다 ㅎ


먼저 아래 그림을 봐라.


각 함수가 어떠한 값을 나타내는지 표현한 그림 이다.


검은색 : RecyclerView에 전체 영역이다.


파란색 : computeVerticalScrollRange 값이다.

          RecyclerView 중 Window에 할당된 영역이다. 

          안드로이드 개발자 분들은 아시겠지만, onBindViewHolder를 부른 상태이다.

          ListView로 보면 getView를 불렀다가 생각 해도 된다.


빨간색 : computeVerticalScrollExtent 값이다.

           화면에서 보여지는 RecyclerView 영역 이다.

          예를 들어 AppBar 와 RecyclerView 가 있는 화면이라고 가정 하자.

          그럼 전체 화면 사이즈가 1280이라 하고, AppBar의 높이가 240정도, StatusBar가 24정도 라고 하면

          1280 - 240 -24 = 1016. 즉 RecyclerView가 보여지는 영역은 1016이 된다.


          즉, 빨간색은 RecyclerView 크기가 변하지 않는 이상 고정 값이라고 보면 된다.


녹색 : computeVerticalScrollOffset 값이다.

        아마 개발 중에 가장 많이 쓰이지 않을까 생각 된다.

        RecyclerView 영역중에서 어느 정도 움직였는지 - 값으로 넘겨 준다.

        -값으로 넘겨주는 이유는 Scroll이 아래로 움직였기 때문이다 ㅋ

        스크롤 상단에서 어느 정도 움직였는지 알려주는 Offset 값이다.

        그래서 얼마나 움직였는지 확인 하고자 할 경우 -1을 곱해주면 된 다.        



처음에 computeVerticalScrollRange 값이 RecyclerView의 전체값인 줄 알고 코딩 했다가

이상한 값이 나와 고생한 적이 있다.

위 내용을 이해하고 개발 로직을 생각하면 좋을 듯 하다.


참고하세요.