Android high imitation wechat dialogue list sliding deletion effect

preface

Those who have used wechat know that the sliding deletion effect of wechat dialogue list is very good. We can also have this effect. The idea is actually very simple. Make a listview, and then make each item into a sliding custom control. Because listview slides up and down and item slides left and right, there will be sliding conflicts. Maybe you need to understand the distribution process of click events in Android. Please refer to Android source code analysis - click event distribution mechanism. My solution is as follows: rewrite the onintercepttouchevent method of listview to judge when moving. If it is sliding left and right, it returns false, otherwise it returns true; Override the ontouchevent method of slideview (that is, a custom item control) to handle sliding. There is no problem with the whole idea, and the sliding conflict has been solved, but the listview can't get the focus, that is, the listview can't handle click events. Let's recall what the problem is: my understanding is that there is no problem with the above handling of sliding, but one side effect is that it will make the outer view lose focus and can't handle click events. Common sliding conflict scenarios, such as embedding a listview inside the launcher, are not a problem, because the launcher does not need to get the focus at this time, and the internal listview needs to get the focus. Therefore, the above processing method is not suitable for external situations that need to obtain focus (for example, the external is listview). So I discussed with ttdevs and found that he adopted another idea. I never thought I could play like this. Here's his idea.

New ideas

Regardless of the complexity and mainstream playing methods, all events are intercepted by the outer listview, and the events are passed to the slideview for sliding. This implementation can indeed achieve results, and the code is very simple. There is no need to deal with any complex sliding conflicts at all.

effect

The following are wechat and high imitation effects respectively

code analysis

Let's first look at how slideview is implemented

Look at the layout XML:

In the above XML file, all views will be placed in view_ Content, and holder is to place things such as delete buttons. Our slideview will load this layout.

Look at slideview java:

The above code has been described in detail. This is the complete code of the sliding control. You should understand that the views you add are added to the child view of the slideview: view_ Content instead of directly adding it to the slideview. Only in this way can we easily make the sliding effect.

Then look at the listview Code: the core is the following method to send the click event to slideview for processing.

Finally, look at the code of activity:

I have specially written comments on the code, so I won't say more.

Code download: http://xiazai.jb51.net/201608/yuanma/androidSlide (jb51.net). rar

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