/ PROJECT, ANDROID, RECYCLERVIEW, FASTSCROLLER

RecyclerView-FastScroller v1.0

RecyclerView FastScroller

RecyclerView에서 FastScroller와 Bubble(현재 아이템 정보)를 지원하는 라이브러리입니다. LinearLayoutManager와 GridLayoutManager를 지원하며, 부드러운 애니메이션을 제공합니다. 간단한 구성으로 핸들뷰와 버블뷰를 먼저 구성하고 RecyclerView와 Bind만 하면 사용 가능합니다.

DEMO

Demo

사용방법은 간단합니다. 핸들뷰를 추가해주세요. 필요하다면 버블을 표시할 뷰도 함께 배치해주시면됩니다. Scroll HandleView가 타겟이 되는 RecyclerView와 같은 부모뷰를 가질 필요는 없지만, 동일한 높이의 부모뷰를 가지고 있어야합니다.

// Bind to RecyclerView
FastScroller(handleView, bubbleListener).bind(recyclerView)

뷰구성 예제

<androidx.constraintlayout.widget.ConstraintLayout>
    ...
        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/items"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
            tools:layout_editor_absoluteX="16dp"
            tools:layout_editor_absoluteY="0dp"/>

        <!-- handle view-->
        <ImageView
            android:id="@+id/handle_view"
            android:layout_width="20dp"
            android:layout_height="40dp"
            android:layout_marginTop="0dp"
            android:layout_marginEnd="0dp"
            android:background="@color/black"
            android:contentDescription="@string/quick_scroll_handle"
            android:scaleType="centerCrop"
            android:src="@drawable/ic_unfold_more_black_48dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent"/>
    
    ...
</androidx.constraintlayout.widget.ConstraintLayout>  

버블뷰

BubbleView를 구성하고, RecyclerView Adapter에 BubbleAdapter 인터페이스를 구현합니다.. BubbleAdapter 인터페이스에는 getBubbleItem()메서드 하나를 가지고 있습니다. 이 메서드는 RecyclerView position에 따른 문자열을 반환하는 메서드입니다. 반환된 문자열은 BubbleListener.setBubble(str:String)를 호출하여 화면에 표시됩니다.

// HandleView
val handleView = findViewById<View>(R.id.handle_view)

// BubbleView (optional feature)
// must implement with BubbleAdapter. see @SimpleAdapter
val bubble = findViewById<View>(R.id.bubble)
val bubbleText = findViewById<TextView>(R.id.bubble_text)
val bubbleListener = object : BubbleListener {
    override fun setBubble(str: String) {
        bubbleText.text = str
    }
    override fun setViewY(y: Float) {
        bubble.y = y
    }
    override fun setVisible(isVisible: Boolean) {
        bubble.visibility = if (isVisible) View.VISIBLE else View.GONE
    }
}

// Bind
FastScroller(handleView,bubbleListener).bind(recyclerView)
<androidx.constraintlayout.widget.ConstraintLayout>
    ...
    <androidx.recyclerview.widget.RecyclerView/>
    <ImageView android:id="@+id/handle_view"/>

    <!-- bubble view-->
    <FrameLayout
        android:id="@+id/bubble"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="4dp"
        android:paddingTop="10dp"
        app:layout_constraintEnd_toStartOf="@+id/handle_view"
        app:layout_constraintTop_toTopOf="parent">

    <TextView
        android:id="@+id/bubble_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:background="@drawable/bubble"
        android:ellipsize="end"
        android:lines="1"
        android:paddingBottom="4dp"
        android:paddingTop="2dp"
        android:paddingStart="10dp"
        android:paddingEnd="20dp"
        android:textSize="20sp"
        tools:text="123"/>
    </FrameLayout>
...
</androidx.constraintlayout.widget.ConstraintLayout>

자세한 내용은 Github의 소스를 내려받아 Example App을 참고부탁드립니다. 문의사항이나 개선요청은 댓글로 남겨주시면, 빠른시일내에 반영하겠습니다.

Todo

  • Smooth Scroll
  • Intelligent ScrollPosition

How to Use

Step 1. Add the JitPack repository to your build file

Add it in your root build.gradle at the end of repositories:

	allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}

Step 2. Add the dependency

	dependencies {
        implementation 'com.github.mond-al:recyclerview-fastscroller:1.0'
	}

Step3. Just Use it!

All you have to do is configure the view and bind it.
If you want, you can also use the bubble function.

// Bind to RecyclerView
FastScroller(handleView).bind(recyclerView)

Search

Get more post