The new version of the Yin Yue Tai APP has a very interesting interactive playback page. You can drag the player down, and the page will become transparent and gradient. Then you can drag it left or right to close the player at the bottom. Then click on the video list and a page will pop up. It's very cool, so I implemented this interactive and cool player page by myself.
1. Without further ado, let’s demonstrate the effect 1.1. Click on a video, then drag your finger up and down, the player will change its size ratio gradually, and the video-related information will change its transparency gradually 1.2. The player can only be dragged left and right when it is at the bottom. At this time, the player has a gradual transparency change. Dragging within a certain range can close the player; then it can only be dragged upward within a short distance of the original position. 1.3. When you click on the video list, if the last video was closed by dragging left or right, there will be a pop-up play page effect; if it is the back key or the back arrow, there will be no effect 2. Explanation of the implementation ideas Undoubtedly, you need to customize a container, handle its touch events, and handle its child Views differently. Touch event handling is best done with ViewDragHelper, and then you need to implement the container onMeasure and onLayout. Due to the use of ViewDragHelper, some pitfalls will be explained during code analysis. The playback page is a question of whether to use a new Activity or just the View of the current Activity. Since the user can slide the video list when the player is reduced to the bottom, I personally think that you can just place a custom container in the current Activity. Therefore, for efficiency considerations, you can use ViewStub for lazy loading. For the convenience of demonstration here, I will directly use the View format. 3. Code analysis 3.1. Required variables 3.2. Initialize ViewDragHelper, then post to get two child Views. It is mandatory to have only two child elements here. 3.3. ViewDragHelper callback needs to do a lot of things. When mFlexView is dragged, the corresponding change effects of mFlexView and mFollowView need to be set at the same time. When mFlexView is released, the closing or folding effects need to be processed. 3.4. Next is to deal with measurement and positioning. The arrangement effect we achieved is similar to the vertical arrangement effect of LinearLayout. Here, the heightUse of measureChildWithMargins is a problem. When onLayout is called and the position cache is not empty, it is directly positioned because ViewDragHelper is processing touch events and the child elements are doing some translation. If an element updates the UI, it will cause a re-layout. For example, my player will do this when updating the time TextView. Therefore, the position is recorded in the onViewPositionChanged method of FlexCallback, and the position can be restored when re-layout. This has also been a pit for a long time. 3.5. Touch event processing. Since scaling will not affect the real width and height of mFlexView, ViewDragHelper will still block the real width and height of mFlexView. Therefore, it is necessary to determine whether the finger falls within the visual range of mFlexView before calling the shouldInterceptTouchEvent method of ViewDragHelper. 3.6. In computeScroll, if mIsClosing is true, the entire translation is closed and the callback event is notified 3.7. The container is implemented. Next, we inherit YytLayout to implement the combined control of the player page, and then encapsulate some common methods. Here we use the famous Ijkplayer to implement the player, shielding the touch events of IjkVideoView and handling them by ourselves; by the way, in order to achieve the effect of the player Controller following the drag and zoom, the commonly used PopupWindow implementation idea is abandoned. IjkController is directly added to IjkVideoView, otherwise it is too troublesome to implement the pop-up window following the player
4. Summary It's not difficult, but it requires imagination to pay attention to the details. You may want to use your imagination when you see the interesting interactions. Next, you may want to realize the effect of UC browser player, which is also very interesting. |
<<: Deep understanding of Swift dispatch mechanism
>>: 9 Best JavaScript Mobile App Development Frameworks
September and October are the golden months, and ...
[[420320]] iPhone users with only 64G or 128G may...
【Software Description】 Muxi reading software is a...
In the past two years, mobile advertising has bro...
BYD's passenger car sales in February 2023 we...
New media operation is a series of operational me...
Friends who have watched the science fiction movi...
A friend who used to work with me in andrology is...
Tik Tok funny video editing tutorial, easily edit...
Not long ago, the water level of the Jialing Rive...
China Science and Technology News Network, Decemb...
Kuaishou and Douyin, as the two representative pl...
[[156376]] There are always so-called experts who ...
The heating of mobile phones is definitely a heada...
Education has always been a common topic, and the...