Android realizes left sliding, and the deletion option appears

The sliding deletion part mainly includes two parts, one is the content area (used to place the normally displayed view), and the other is the operation area (used to place the deletion button). By default, the operation area is not displayed, the size of the content area is to fill the entire container, and the operation area is always on the right of the content area. When you start sliding, all child views in the whole container slide to the left. If the operation area is invisible at this time, it is set to visible.

The implementation idea is to customize a layout. Swipelayout inherits from FrameLayout. Swipelayout contains two sub views. The first sub view is the content area and the second sub view is the operation area. The control of sliding effect is mainly realized by detecting the touch event of swipelayout. In fact, viewdraghelper has been provided in Android support library to monitor touch events.

1. First, you need to overload the LinearLayout

See notes for specific analysis

Because I set the outer margin for my LinearLayout, there will be up and down sliding in the process of sliding to the left, and the original position of the item will also be offset. To solve this problem, you first need to modify the data according to the margin value you set

Add onviewpositionchanged to

Modify to fit the data to prevent the slider on the right from not hiding

Add on

To limit the value of top moving up and down, you still need to think about it yourself

2. Writing layout files

Specific effect

But there is still a problem

Click event and slide event of each item in listview cannot coexist. On the Internet, it is said that the trigger of an event is passed down to the component handling the event layer by layer, and then the processing result is returned up layer by layer.

The above is what Xiaobian introduced to you. The deletion option appears when Android realizes left sliding. 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
分享
二维码
< <上一篇
下一篇>>