Android ListView slide effect implementation (sliding expansion, sliding deletion), androidlistview

Source: Internet
Author: User

Android ListView slide effect implementation (sliding expansion, sliding deletion), androidlistview

Reprinted please indicate the source: http://blog.csdn.net/lonelyroamer/article/details/42439875


The project requires the effect of ListView sliding deletion. First of all, it must be tailism. I searched the internet and found a lot of such things. The SwipeListView on Github is quite famous. However, I tried it and found that it had many bugs and could not achieve the desired effect. As a result, I tried other examples and found that there were many problems with the basic effects. Either event conflict, OnItemListView, or a Button cannot respond. No way. You can only write one by yourself.

At the very beginning, I wrote the simplest one. It only supports slide on the right side and only supports one slide mode. I will first use it in the project. Then I want to complete the project and write it on and off for a while. During the release of Android5.0, the new control RecyclerView will replace the position of ListView. I felt that I had done nothing, and then I was interrupted.

However, we later found that RecyclerView is a new control. Many third-party libraries based on ListView do not have RecyclerView (fewer users are used, and no one writes it ). So I picked it up and wrote it again. Maybe it will be used later.


Let's take a look at the running demo effect,



The implementation details are not described, and the complete code will be uploaded later. Let's talk about the problem.

1. Add the 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="200"        slide:slideLeftAction="scroll"        slide:slideMode="both"        slide:slideRightAction="scroll" />

2. inherit the SlideBaseAdapter and override the getFrontViewId (), getLeftBackViewId (), and getRightBackViewId () methods.

@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;}
A single Item can be slide sideways, depending on three points, priority from top to bottom.

(1) Whether you provide LeftBackView or RightBackView for this Item

(2) There is a method in the SlideBaseAdapter that can change the SlideMode of a position. You can change the SlideMode of a position separately.

/** * At first,your whole item slide mode is 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 SlideMode getSlideModeInPosition(int position) {return mSlideMode;}

(3) The value of SlideMode set by your SlideListView


3. SlideAction indicates the method of Slide and expansion. Currently, there are two types of SCROLL and REVEAL. The results are as follows:

SCROLL:


REVEAL:


4. If your front view and back view are combined with multiple views, you must also rewrite the getItemViewType () and getViewTypeCount () methods. Otherwise, the view may be messy during reuse.

@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;}

It is a great pleasure to use this code to help you. If you have any bugs, please correct them.

Some people say that you need to score points when uploading a resource. Okay, don't score points this time. The download stamp is here (it is still under review. After review, click the URL again. It seems that the above GIF image is useless. I sent it to see if it is useless)






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.