mirror of
https://github.com/CappielloAntonio/tempo.git
synced 2026-02-02 07:23:36 +00:00
Added a custom snap helper in recyclerview
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package com.cappielloantonio.play.helper.recyclerview;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.LinearSnapHelper;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
public class CustomLinearSnapHelper extends LinearSnapHelper {
|
||||
@Override
|
||||
public View findSnapView(RecyclerView.LayoutManager layoutManager) {
|
||||
if (layoutManager instanceof LinearLayoutManager) {
|
||||
LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
|
||||
if (!needToDoSnap(linearLayoutManager)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return super.findSnapView(layoutManager);
|
||||
}
|
||||
|
||||
public boolean needToDoSnap(LinearLayoutManager linearLayoutManager) {
|
||||
return linearLayoutManager.findFirstCompletelyVisibleItemPosition() != 0 && linearLayoutManager.findLastCompletelyVisibleItemPosition() != linearLayoutManager.getItemCount() - 1;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user