Android implements the sideslip deletion of QQ class based on swiperefreshlayout

preface

I remember last year, when I did a chat project, I needed to achieve a pull-down refresh similar to QQ and have the function of sideslip deletion. After looking for QQ on the Internet for a long time, there were more or less various problems. Finally, after removing the pull-down refresh function, I only retained the function of sideslip deletion to find a perfect one. After going back to discuss with a friend, the friend said after looking for it. This function can't be written without more than 8K (⊙ n ⊙ b). Now it seems that it was really naive. Now I don't have 8K. I still try to write and practice by the way.

Or renderings first

The solution of event sliding can't be seen in the rendering (or I don't know how to record the sliding direction and click of my finger on the screen. Please tell me, thank you). For details, you can download it from GitHub below.

Let's see how to use it first

First, the portal address swipemenurefreshview

This project refers to the specific address of a sideslip menu library, androidswipelayout (this is a very powerful library that can slide up, down, left and right. For details, please go to its GitHub)

quote

Layout file

Item layout file

Concrete implementation

1. Realization idea

In fact, the idea is very simple, that is to rewrite onintercepttouchevent in the implementation of custom swiperefreshlayout to intercept and distribute events according to whether they slide left or right or up or down

2. Judge the sliding direction

It mainly determines whether to slide up and down or left and right according to the included angle of the user's sliding. After judgment, set a flag. If the next slide is listivew, call the onintercepttouchevent method of the parent class to slide normally. At this time, the event has been consumed when it reaches the sideslip menu, and all events will not slide out of the sideslip menu. If it is left-right sliding, return false does not intercept the event. The event is handled by the child control. This is left-right sliding. The listview will not consume, so it will reach the sideslip menu for processing.

3 Click event handling

Click events are divided into several situations

1. Click on a common item: no processing will be done in this case

2. When you click another item after sliding out of the sideslip menu bar, this is to judge whether it is the position of the sideslip menu currently sliding out. If it is not in the down event, close it and return true. When you return true in onintercepttuchevent, all events thereafter, All operations until the finger is lifted are handled by its own ontouchevent, and no operation is done in ontouchevent to directly intercept to achieve the desired effect

Judge whether it is the item of the current slide out menu

3. When the user clicks the current sideslip menu, there are two cases. If the clicked range is not the range of the sideslip menu, return false. At this time, if the user raises his hand within the range of the sideslip menu, a click event (if any) will be triggered. If not, the sideslip menu will be closed. If there is a move event during this period, that is, the user has a slide, it will enter the move judgment logic mentioned earlier.

Has the final say that the Item is not the one that you can say. If you have slipping, you can start with the parent class and then do the logic. This is not the son has the final say.

epilogue

This article distributes a lot of knowledge about design events. In addition, these controls have their own methods. Many contents are not easy to say clearly (even they may not be very clear). In addition, my expression ability is not good, so it may be cloudy. If you are interested, you can go to GitHub to download the source code. Finally, after giving the address swipemenu refreshview once

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