-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomLinearSnapHelper.java
More file actions
42 lines (29 loc) · 1.07 KB
/
Copy pathCustomLinearSnapHelper.java
File metadata and controls
42 lines (29 loc) · 1.07 KB
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
import android.support.v7.widget.LinearSnapHelper;
import android.support.v7.widget.RecyclerView;
import android.view.View;
public class CustomLinearSnapHelper extends LinearSnapHelper {
private RecyclerView recyclerView;
private int selectedPosition;
public CustomLinearSnapHelper(RecyclerView recyclerView, int selectedPosition)
{
super();
this.recyclerView = recyclerView;
this.selectedPosition = selectedPosition;
}
@Override
public View findSnapView(RecyclerView.LayoutManager layoutManager) {
View view = super.findSnapView(layoutManager);
if (view != null) {
final int newPosition = layoutManager.getPosition(view);
if ( newPosition != selectedPosition && recyclerView.getScrollState() == RecyclerView.SCROLL_STATE_IDLE) {
onViewSnapped(newPosition);
selectedPosition = newPosition;
}
}
return view;
}
private void onViewSnapped(int position)
{
//...
}
}