Implementation of Android Netease tab sorting control

First look at the renderings:

1. XML layout import

2. Set the data source data, that is, the corresponding text data of each item

3. Set listening for interactive click and long press events

4. Interface to start and end sorting

Imperfect customization function

1. At present, only string is supported, and the layout cannot be customized. In the future, the custom input of the view of the item of tab may be improved

2. At present, the number of lines and spacing of layout are controlled by hard code, and there is no easy to understand interface leak

PS: the method of debugging spacing, mainly debugging the following parameters

3. The rollback is not smooth. Later, you can introduce a scroller to control the slow rollback

Implementation principle

1. The layout item sorting adopts the custom layout based on ViewGroup. The method logic of onlayout calculates the configuration according to the parameters in the configuration parameter area

2. In the sliding module part, according to the capture of coordinates in ontouchevent, analyze the corresponding sub items according to the coordinates, and use the view. Layout () method to make the dragged view follow the finger to participate in the code

3. For the animation module, considering the low version and not wanting to introduce too many open source libraries, ordinary animation is adopted. See the beginanimation (final int start, final int end, Boolean forward) method for details.

4. Overall process

a. The down event of touch captures the current X and Y data, calculates the corresponding index of the moved view, and the other views begin to shake the animation

b. For the move event, use the layout method to follow the finger movement of the selected view according to X and y

c. Up event, execute the position adjustment animation, and set the new position after the adjustment

Full code: https://github.com/ganchuanpu/SortTabLayout.git

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