Android entry drag and drop function instance code
According to the requirements of the project, the effect of dragging and deleting items should be done. The actual effect is the same as that of QQ message deletion. Sideslip has formulation and deletion.
design sketch
Effect drawing of the first step
1.0 custom control swipelayout inherits FrameLayout and overrides the three construction methods inside, calling initview () respectively
2.0 using custom controls in layouts
3.0 in the initview() method, create the drag helper viewdraghelper()
This method requires the incoming callback mycallback()
4.0, create mycallback() callback and inherit viewdraghelper.callback
Override the trycaptureview method in the callback, return true, allow the child to be dragged, override the clamviewpositionhorizontal, and return the drag position provided by the left system
5.0 onintercepttouchevent return: let viewdraghelper judge whether to intercept the event
6.0 ontouchevent returns true and lets the viewdraghelper analyze the event
Specific code:
Layout:
Swipelayout Code:
Step 2:
1.0 create onfinishinflate method to obtain child controls and judge robustness
2.0 create the onsizechanged method and call it when the control size changes to obtain the width and height of the control and the maximum moving range of the deleted panel
3.0 specify the position of the side pull panel in onlayout
4.0 realize linkage effect in onviewpositionchanged method
5.0 fix the horizontal position of the dragged control in the clapviewpositionhorizontal method,
Step 3:
design sketch
In 1.0 onviewreleased, judge whether to open or close according to the start of the game
2.0 first slide in movecontent
In 3.0 computescroll, continue sliding until it reaches the specified position
4.0 note that in onviewpositionchanged, manually refresh the interface and call the invalidate method
If the interface is not refreshed manually, the effect will not be displayed
Step 4:
1.0 now assign a value to listview, which is omitted here
2.0 using enumeration in swipelayout to record the status of the panel
3.0 / / record the last open panel. Note: it must be a static variable
4.0 create a method operation in onviewpositionchanged to close the panel
5.0 closepre() in this method, judge the status of the current panel, and close the last open panel according to the status
summary
The above is the Android entry drag and drop function example code introduced by Xiaobian. 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!