Android ListView Slider effect Implementation (swipe to expand, swipe to delete)

Source: Internet
Author: User

Reprint Please specify source: http://blog.csdn.net/lonelyroamer/article/details/42439875


The project needs to be the ListView sliding deletion effect, first of all certainly is take doctrine, searched on the net once, discovered this kind of thing really many, compares the famous GitHub on the Swipelistview. But the individual tried it, found it a lot of bugs, and did not achieve the effect I want. So I tried another example and found that the basic effects were there, but there were a lot of problems. Either the event conflicts or the Onitemlistview or a button cannot respond. No way, you can only start writing one.

At first, I wrote the simplest, only support the right side of the slide, and only support a sliding mode, first used in the project. And then want to improve the project, intermittent write for a period of time. During the Android5.0 release, the new control Recyclerview will replace the ListView status. Suddenly feel that they did not work hard, and then interrupted.

But later found that Recyclerview is a new control, a lot of third-party library based on the ListView, Recyclerview not (with fewer people, naturally no one to write). So I picked it up and re-wrote it, maybe it will be used later.


First look at the running demo effect,



The specifics of the implementation are not described, and the complete code is uploaded later. Talk about the use of the problem.

1. Add a control to your layout file:

    <com.roamer.slidelistview.slidelistview        xmlns:slide= "Http://schemas.android.com/apk/res-auto"        Android:id= "@+id/list_view"        android:layout_width= "match_parent"        android:layout_height= "Match_parent"        slide:slideanimationtime= "slide:slideleftaction="        scroll "        slide:slidemode=" both "        slide: sliderightaction= "Scroll"/>

2, Inherit Slidebaseadapter, rewrite inside the Getfrontviewid (), Getleftbackviewid (), Getrightbackviewid () method.

@Overridepublic int Getfrontviewid (int position) {return r.layout.row_front_view;} @Overridepublic int Getleftbackviewid (int position) {return r.layout.row_left_back_view;} @Overridepublic int Getrightbackviewid (int position) {return r.layout.row_right_back_view;}
One item can be slippery, depending on three points, priority from top to bottom.

(1), do you provide Leftbackview or Rightbackview for the item?

(2), there is a method in Slidebaseadapter, you can change the slidemode of a position, you can change the slidemode of a position alone

/** * at First,your whole item slide mode are base on the Slidelistview's * slidemode.<br/> * but your can change the Slide mode at one or more position in this * adapter by override this method *  * @param position * @return */public S Lidemode getslidemodeinposition (int position) {return mslidemode;}

(3), your Slidelistview set the value of the Slidemode


3, Slideaction said side-by-side expansion of the way, there are currently two kinds of scroll and reveal. The results were as follows:

SCROLL:


REVEAL:


4. If your front view and back view are combined to have multiple views, you must also rewrite the Getitemviewtype () and Getviewtypecount () methods, otherwise the view will be confused when reused

@Overridepublic int Getfrontviewid (int position) {return r.layout.row_front_view;} @Overridepublic int Getleftbackviewid (int position) {if (position% 2 = = 0) {return r.layout.row_left_back_view;} return R.layout.row_right_back_view;} @Overridepublic int Getrightbackviewid (int position) {return r.layout.row_right_back_view;} @Overridepublic int Getitemviewtype (int position) {if (position% 2 = = 0) {return 0;} return 1;} @Overridepublic int Getviewtypecount () {return 2;}

If that code helps you, it's a great honor. If there is a bug, please correct me.

Some people say you have to upload a resource to divide, OK, this time do not divide. Download stamp here (still in review, after the review of the link address. It's like the gif above doesn't work, I sent it to see if it's useless.






Android ListView Slide-Slip effect (slide expand, swipe to delete)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.