fereframe.blogg.se

Android studio recyclerview swipe to delete
Android studio recyclerview swipe to delete







android studio recyclerview swipe to delete

I tested out using ‘match_parent’ and the top layer did a good magic trick and disappeared. Make sure to use ‘wrap_content’ or a predefined width for your bottom layer.Ensure the bottom layer is the first layout component within the SwipeRevealLayout container.For an example of how to set it up: list_item_main.xml Adjust your layout code for your RecyclerView ViewHolder and add the SwipeRevealLayout component as the container for both the top and bottom layer of your RecyclerView Item.Add the following class to your project: SwipeRevealLayout.java.In this case, the swipe is going to be in the positive X axis, so we need to check if the direction is ItemTouchHelper.RIGHT.

android studio recyclerview swipe to delete

This method is going to contain all the logic that was explained before.Īnother method that we are going to use is o nSwiped, this where we define an action that triggers when a swipe is done in a specific direction (for example, a removal of a row in the app database). To develop this animation we need to override the SimpleCallback class, with special attention to the onChildDraw method, which is going to be called every time the screen is updated, meaning that in a display with a 60 Hz refresh rate, the function is called every 16 ms. The icon and the circle are drawn in the child view using the calculations done previously.The centre of the icon is calculated, which is also the centre of the circle, and the space in which the icon is going to be shown is defined.Based on how much the item has been moved in the X axis, we define the size of the icon, its colour and the radius of the circle that is going to resize throughout the animation.Coordinates when the swipe is considered to be effective are saved.Parent view coordinates are obtained so that child view coordinates can be calculated too.We are going to trigger the animation every time a swipe is detected over our item with the next algorithm: This is important to understand the code later. Remember that in Android the (0,0) coordinates are in the top left corner of the screen. Child and Parent View in a RecyclerView item









Android studio recyclerview swipe to delete