Android listview sliding delete operation (swipelistview)

The sliding deletion function introduced in the new version of wechat and QQ is a popular function now. In fact, this sliding deleted control is already available on GitHub. It is a popular open source framework swipelistview. However, the swipelistview is a FrameLayout, that is, a two-layer layout. The front of the upper layout covers the back of the lower layout. When sliding, the front will be opened, so that the back of the lower layout will be displayed. However, after looking at the sliding deletion of wechat, it seems that this is not the case. It feels more like a single-layer layout beyond the screen. When sliding, the button on the right beyond the screen enters the screen. I guess it should not use the swipelistview control. The sliding deletion of QQ hides a button on the right of the item in the listview, but when a sliding event is detected, give the button an animation to make it visible. This scheme should be the best implementation.

This article mainly studies the open source framework swipelistview.

There are two ways to use this framework. One is to import the swipelistviewlibrary project as a dependent Library of an Android project. Because the swipelistview library project itself also relies on another popular open source framework, nineold androids, this can also be easily found on the Internet or GitHub.

Import these two library projects. For nineoldandroids, the following settings are made. In fact, the main thing is to check the option is library, so that the nineoldandroids project can be used as the dependent Library of other projects:

For swipelistviewlibrary, in addition to checking the is library option, remember to add the above nineoldandroids in the next add as the dependent Library of this library:

The following is how to use this library. First, clean the above two library projects. Many times, there are engineering errors. Just clean it. Then create your own project and add the swipelistviewlibrary project in the Add option. In this way, you can directly use the swipelistview control. The code is as follows:

The app: swipefrontview attribute specifies the ID of the view of the upper layer in the FrameLayout mentioned above, and the app: swipebackview specifies the ID of the view of the lower layer. You can see it in the layout of the item to be used by the custom basedatpter below:

Code initialized in activity:

And customize getview () in baseadapter:

Then it's OK. The effect of running the project is as follows:

Another way to use swipelistview control is to directly import the two official jar packages, which can be seen in the opening address above, but importing these two jar packages directly does not mean that they can be used immediately! First, add this package to the build path of the new project. If your project does not add Android support package android-support-v4 Remember to add the following jar, and then remember to import res \ values \ swipelistview from the swipelistview library project you have imported earlier__ attrs. The XML file is copied to the RES / values / directory of the new project. This file is mainly used to declare the attributes in the swipelistview control. The directly imported jar package does not contain files to declare these attributes. Then it is referenced in the code like the above, but two points need to be noted: first, the package name of swipelistview in jar package is different from that in library project, so you need to pay attention to the following when referencing; 2、 After you are ready and confirm that the previous steps are correct, sometimes you report an error when compiling the project, saying that the swipefrontview and swipebackview attributes are not declared. This problem seems to be a bug in the swipelistview framework. Someone pointed out on stackoverflow to the effect that it is worth declaring the swipefrontview and swipebackview attributes in the layout file, It's best not to customize the name of the ID, but to use swipelistview_ Backview and swipelistview_ frontview。

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

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
分享
二维码
< <上一篇
下一篇>>