Nonsense not to say more, directly to everyone paste code. The specific code looks like this:
<?xml version= "1.0" encoding= "Utf-8"?> <relativelayout xmlns:android= "http://schemas.android.com/apk/res/" Android "xmlns:tools=" Http://schemas.android.com/tools "android:layout_width=" Match_parent "android:layout_height = "Match_parent" tools:context= "c.example.jreduch10.recycler1activity" > <
Android.support.v7.widget.RecyclerView android:layout_width= "match_parent" android:layout_height= "Match_parent" Android:id= "@+id/rv" ></android.support.v7.widget.RecyclerView> </RelativeLayout> <span style= " font-size:18px; "
>package c.example.jreduch10;
Import Android.os.Bundle;
Import android.support.v7.app.AppCompatActivity;
Import Android.support.v7.widget.LinearLayoutManager;
Import Android.support.v7.widget.RecyclerView;
Import Android.support.v7.widget.helper.ItemTouchHelper;
Import Android.util.Log;
Import Android.view.View;
Import Android.view.ViewGroup;
Import Android.widget.ImageView;
Import Android.widget.TextView; Import Android.widget.Toast;
Import java.util.ArrayList;
Import java.util.List;
Import C.example.jreduch10.entity.video;
Import Jp.wasabeef.recyclerview.adapters.AlphaInAnimationAdapter;
Import Jp.wasabeef.recyclerview.adapters.ScaleInAnimationAdapter;
public class Recycler1activity extends appcompatactivity {private Recyclerview RV;
Private list<video> List;
Private Adapter Adapter;
Private Itemtouchhelper Itemtouchhelper;
@Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_recycler1);
rv= (Recyclerview) Findviewbyid (R.ID.RV);
List=new arraylist<> ();
InitData ();
Adapter=new adapter (list);
Linearlayoutmanager llm=new Linearlayoutmanager (this);
Llm.setorientation (linearlayoutmanager.vertical);
Rv.setlayoutmanager (LLM);
Rv.setadapter (adapter);
Animation effect Alphainanimationadapter alphainanimationadapter=new Alphainanimationadapter (adapter); Rv.setadapter (New Scaleinanimationadapter (Alphainanimationadapter));
Default animation effect//Rv.setitemanimator (New Defaultitemanimator ());
Itemtouchhelper=createitemtouchhelper ();
Itemtouchhelper.attachtorecyclerview (RV); Listens for a line of events//Recyclerviewitemlistener listener=new Recyclerviewitemlistener (This, new Recyclerviewitemlistener.onitemclicklistener () {//@Override//public void Onitemclick (View item, int adapterposition)
{//Toast.maketext (Getbasecontext (), adapterposition+ "", Toast.length_short). Show ();
// }
// });
Rv.addonitemtouchlistener (listener); Public Itemtouchhelper Createitemtouchhelper () {itemtouchhelper=new itemtouchhelper (new Itemtouchhelper.callback ()
{@Override public int getmovementflags (Recyclerview recyclerview, Recyclerview.viewholder viewholder) {//drag-supported direction up
int Dragflags=itemtouchhelper.up|itemtouchhelper.down; The direction of support when sliding is left and right int swipeflags=itemtouchhelper.left|
Itemtouchhelper.right;
The Makemovementflags () method must be invoked to notify the type return Makemovementflags (DRAGFLAGS,SWIPEFLAGS) supported by the Touchhelper;
///Drag the callback secondary method up and down. @OverrIDE public boolean onmove (Recyclerview recyclerview, Recyclerview.viewholder Viewholder, Recyclerview.viewholder
Target) {Adapter.move (Viewholder.getadapterposition (), target.getadapterposition ());
return true;
//left and right to callback this method. @Override public void onswiped (Recyclerview.viewholder viewholder, int direction) {Adapter.delete (
Viewholder.getadapterposition ());
@Override public boolean isitemviewswipeenabled () {return super.isitemviewswipeenabled ();
@Override public boolean islongpressdragenabled () {return super.islongpressdragenabled ();
}
});
return itemtouchhelper;
public void InitData () {video video=new (R.MIPMAP.ZYF, "homemade", "...");
List.add (video);
Video=new Video (R.MIPMAP.ZYFZYF, "homemade", "...");
List.add (video);
Video=new Video (R.MIPMAP.ZYFZYFZYF, "homemade", "...");
List.add (video);
Video=new Video (R.MIPMAP.ZYF, "homemade", "...");
List.add (video);
Video=new Video (R.MIPMAP.G, "homemade", "...");
List.add (video); Video=new Video (R.mipmap.ic_launchEr, "domestic", "...");
List.add (video);
Video=new Video (R.MIPMAP.ZYF, "homemade", "...");
List.add (video);
Video=new Video (R.MIPMAP.ZYF, "homemade", "...");
List.add (video);
Video=new Video (R.MIPMAP.ZYFZYF, "homemade", "...");
List.add (video);
Video=new Video (R.MIPMAP.ZYFZYFZYF, "homemade", "...");
List.add (video);
Video=new Video (R.MIPMAP.ZYF, "homemade", "...");
List.add (video);
Video=new Video (R.MIPMAP.G, "homemade", "...");
List.add (video);
Video=new Video (r.mipmap.ic_launcher, "homemade", "...");
List.add (video);
Video=new Video (R.MIPMAP.ZYF, "homemade", "...");
List.add (video);
public class Adapter extends recyclerview.adapter<viewholder>{private list<video> mdata;
Public Adapter (list<video> mdata) {this.mdata=mdata;
Call this method public void Delete (int position) {Mdata.remove (position) when sliding around;
notifyitemremoved (position);
Call this method public void move (int from,int to) {video video=mdata.remove (from) when dragging up and down;
Mdata.add (To>from?to-1:to,video); Notifyitemmoved (FROM,TO);
@Override public int GetItemCount () {return mdata.size (); @Override public Viewholder Oncreateviewholder (viewgroup parent, int viewtype) {View view=getlayoutinflater (). Inflat
E (R.layout.recycle1_linear_layout,parent,false);
Viewholder vh=new viewholder (view);
return VH;
@Override public void Onbindviewholder (viewholder holder, int position) {video video=mdata.get (position);
Holder.iv.setImageResource (Video.getimg ());
Holder.title.setText (Video.gettitle ());
Holder.content.setText (Video.getcontent ());
} public class Viewholder extends recyclerview.viewholder{ImageView IV;
TextView title;
TextView content;
Public Viewholder (View Itemview) {super (Itemview);
iv= (ImageView) Itemview.findviewbyid (R.ID.IV);
Title= (TextView) Itemview.findviewbyid (r.id.title);
Content= (TextView) Itemview.findviewbyid (r.id.content); Listen for event one item Itemview.setonclicklistener (new View.onclicklistener () {@Override public void OnClick (view view) {int posi Tion=getadaptErposition ();
LOG.D ("9999999999", "uuuuu");
Toast.maketext (Getbasecontext (), Title.gettext () + ":" +position,toast.length_short). Show ();
}
}); }} </span>
The above is a small set to introduce the Android sliding monitor Recyclerview linear flow + left and right delete + Move up and down, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!