Use the recelerview to complete the drag sort high imitation QQ sideslip deletion function

Recently, the receleroview has been used to complete drag sorting and sideslip deletion. Record it here.

You need to use: itemtouchhelper The callback class.

design sketch:

In an activity with a recylerview, in addition to setting the adapter, you also need to do the following:

The operation in activity is so simple.

Next, define an interface to decouple, because I see some articles dealing with onmove and onswape in the activity, which can be abstracted for better understanding.

Implement this interface in the adapter of recylerview,

Copy the above two methods,

In this way, the work of the adapter is completed. It is also very simple. There is a fixed routine. Note that the demo you see has a default animation. The animation effect is that when you set the recylerview Setitemanimator (parameter); If you do not call this method, it is the default animation effect.

In addition to setting the adapter, you also need to do the following:

Write a class to inherit itemtouchhelper Callback, which is the last step, is also the class instantiated in activity at the beginning of this article,

There are not many codes:

So far, a simple drag and sideslip is completed. In fact, the logic of drag and sideslip is the same. Follow the above steps and the effect will come out.

The above is just a simple effect. After realizing the above effect, let's look at the more advanced effect:

RecycleViewSwipeDismiss

To achieve the above effect, first talk about the above logic:

First, the layout of each item is two layers:

Principle: the full screen linear layout is responsible for the sideslip effect, and the root layout is the layer with color and pictures. Because the linear layout is slid away, the root layout and the pictures above come out.

Several methods for re replication in myitemtouchhelpercallback and several methods for multi replication:

The method of getdefaultuiutil () specifies that the sliding operation is LinearLayout, so only LinearLayout is slid away each time. Other operations are the same.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>