Android imitation Sina Weibo / QQ space sliding automatic video playback function

Let's take a look at the renderings first

critical code

1. Listen for scrolling events

First, add setonscrolllistener listener to listview. Note that this listener is addonscrolllistener on recyclerview, that is, the following code supports recyclerview at the same time.

There are two methods in monitoring. We use onscroll method to record the current first visible item and the total number of visible items, and use onscrollstatechanged to monitor the whole process of hand sliding the screen. When the scrollstate field value in onscrollstatechanged is equal to scroll_ STATE_ When idle, it means that the sliding is completed and the rolling is stopped 🙄 Interested friends can Baidu the meaning of the other two parameters, which may be helpful to your needs 🙄。

2. Processing video logic

First, judge whether the item has video according to the total number. If so, use the rect class to obtain the visual area of the view in the screen coordinates.

Summary

Well, the basic core code is the above, isn't it very simple? If you are interested, please do it yourself. I hope this article can be helpful to you. If you have any questions, you can leave a message.

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