Rebound
Add IOS-style scrolling animation to your scrolling views with SpringAnimation.
Currently includes BouncyRecyclerView and BouncyNestedScrollView.
In your build.gradle application module :
Dependencies { implementation
androidx.recyclingerview:recyclingerview:1.1.0
implementation com.factor:bouncy:1.61
}
(BouncyRecyclerView requires androidx.recyclerview).
NestedScrollView with a bouncing scroll effect, currently only supports vertical scrolling.
Obtained by canceling the standard side effect.
Usage:
Use as a normal NestedScrollView. Put it in the layout:
…
…
…
fling_animation_size defines the size of the fling effect for the fling, the default is 0.5 if no value is specified.
overscroll_animation_size sets the value of the overscroll effect for dragging, the default is 0.5 if not specified.
It is strongly recommended to keep these two values below 5.
BouncyRecyclerView adds a scrolling effect to the RecyclerView and supports drag-and-drop gestures.
Usage:
Use as a normal RecyclerView. Put it in the layout:
install the layout manager and the adapter. Theoretically, any LayoutManager is supported:
recycle_view.setAdapter(myAdapter);
recycle_view.setLayoutManager(new LinearLayoutManager(context));
//recycle_view.setLayoutManager(new GridLayoutManager(context, 3))
Setting
The fling_fling_animation_size parameter determines the size of the fling effect for the fling, the default is 0.5 if no value is specified.
The default value is 0.5 if not set.
allow_drag_reorder and allow_item_swipe are set to false by default. If you want to activate these functions, you only need to set them.
Spring adjustment (kickback 1.6 and above)
view_damping_coefficient and view_statistics of the recycling company, note the damping and stiffness data
Enter the code:
recyclinger_view.setFlingAnimationSize(0.3f) ;
recyclinger_view.setOverscrollAnimationSize(0.3f) ;
recyclinger_view.setDampingRatio(Bouncy.DAMPING_RATIO_HIGH_BOUNCY) ;
recyclinger_view.setStiffness(Bouncy.STIFFNESS_HIGH) ;
A known problem is that when setting spring properties, elements at the edges of the screen may be cut off, because the current implementation animates the Y-offset of the entire image of recyclable materials. One solution is to put a BouncyRecyclerView inside a NestedScrollView (not necessarily a BouncyNestedScrollView) :
Drag and drop
Shooting and posing doesn’t work from the start.
To make the drag and drop or drag-and-drop gestures work, expand your adapter with BouncyRecyclerView.Adapter and add a constructor that matches the parent.
(If your adapter is not distributed by BouncyRecyclerView.Adapter, BouncyRecyclerView simply disables gestures).
The public class MyAdapter extends the BouncyRecyclerView.Adapter
{
private final ArrayList dataSet ;
public MyAdapter(ArrayList dataSet)
{
this.dataSet = dataSet ;
}
@Check
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
{
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item, parent, false);
returns new MyViewHolder(view);
}.
@ address
public void opBindViewHolder(RecyclerView.ViewHolder, int position)
{
MyViewHolder h = (MyViewHolder) holder;
h.getTextView().setText(dataSet.get(position).getData());
}
@Override
public int getItemCount()
{
return dataSet.size();
}
@Override
public void onItemMoved(int fromPosition, int toPosition)
{
//***** must be overwritten to save changes
///repeated call when dragging an item (reordering)
// Example of processing reorganization
MyData item = dataSet.remove(fromPosition);
dataSet.add(toPosition, item);
notifyItemMoved(fromPosition, toPosition);
}.
@Check public empty
onItemSwipedToStart(RecyclerView.ViewHolder viewHolder, int position)
{
/Moved item to left
}
@Check public empty
onItemSwipedToEnd(RecyclerView.ViewHolder viewHolder, int position)
{
/Moved item to the right
}
@Top
public void onItemSelected(RecyclerView.ViewHolder viewHolder)
{
//Item long pressed (selected)
}
@General empty
onItemReleased(RecyclerView.ViewHolder viewHolder)
{
//element released (not selected)
}
}
See also the example of Kotlin
GitHub
Related Tags:
android overscroll effect, android recyclerview overscroll bounce, android overscroll animation, overscroll-behavior android, elastic scrolling android, android:overscrollmode, recyclerview overscroll listener, android-scrollview bounce effect