Android development imitates the sliding deletion function of QQ list information

The completion of this effect is mainly divided into two parts

Custom view is the list item of listview. A view includes a contentview that displays avatar, name, message content, etc. and a delete that can only be displayed by sliding. The top right menu menuview changes the position of these two views when your finger moves

Rewrite listview to determine whether the item slides left or right, normal scrolling or left-right sliding, etc. rewrite ontouchevent for event distribution

General idea:

Listview distributes events to determine whether sliding or scrolling is required. If sliding is required, pass the event to item for sliding processing. Control contentview and menuview to change the position in item to complete the scrolling effect

Rewrite listview code

Override item item

The sliding effect of view is completed in the, using the scroller class

The article on the use of scroller has been pasted with a post of great God at the end. Students who do not understand can understand the use of scroller first. It is good to understand the sliding effect. I will talk about it briefly here

This class does not actually complete the scrolling effect. It is an auxiliary class for calculating the movement track of the control. For example, this class calculates the movement value from position 0 to position 100 within 1 second. It does not complete the sliding effect, but tells us the sliding process. The actual view movement operation is in computescroll() To complete this method, we need to rewrite the built-in method of view

What about the computescroll method? The source code itself is empty, waiting for us to implement. The code that actually changes the view location is called in this method

Um... General English

When we want to achieve a scrolling effect through the scroller, the parent layout will call this method to update the position of the child view

The official description is: when we execute ontouch or invalidate () or postinvalidate (), this method will be executed

In this method, the moving distance is continuously obtained, and the location of the view is updated through the layout () method of the view

Adapter

Reference documents:

Swipemenulistview is an open source project on GitHub to achieve this effect

The above is what Xiaobian introduced to you. It imitates the sliding deletion function of QQ list information in Android development. I hope it will be helpful to you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

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