mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 09:53:33 +00:00
Added a custom snap helper in recyclerview
This commit is contained in:
parent
a3d01e1425
commit
3e9ae1bb6c
5 changed files with 72 additions and 6 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue