Android App Development
iOS App Development
Flutter App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 220.127.116.11 release ready!
In last blog, we discussed how to make items in your recycler view swipeable , now we are going to discuss how to make this happen partially and display some other thing say (png file) in place of the displayed view.
A perfect example for this would be deleting the item from recycler view list with the permission of the user.
If you have followed the last blog then implementing this is pretty easy as there is nothing new this time.
First create a simple callback of the ItemTouchHelper class, override its onSwiped and onChildDraw method, and attach it to your recycler view and its done .
Now lets have a look at the code :
This time there is nothing new except that we have set the TranslationX value to dX/5 .
The dX value tells you about the direction in which your item has moved and it ranges from 0 (not moved) to 1(fully swiped) . And the sign before the dX value tells you about the direction (-ve means item has moved left and +ve means item has moved right).
This being said i have used the dx/5 value as it suited my case, you can choose any value depending on your use case.
Now the second important change that you will notice is in the line where “icon” is initialized , here we have decoded a png file into corresponding bitmap and then displayed it in a rectangle with name “icon_dest” and when you will see the “icon_dest” initialization line , you will notice the bounds that i have made, these are just to make the icon appear in center and good looking with my recycler view item.
Now you just need to attach this code to your recycler view,
For this you just need to add two lines in your piece of code :
And all is done , build your project and see how it looks and change the calculaltions as per your need 🙂
Keep coding and Keep sharing 🙂
Your email address will not be published. Required fields are marked*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
Great Product, Great Team, and Great Support Service. And if you want to add more features to the product, they can submit any idea that comes to your mind. They really care about their clients and we are really happy and honored to deal with Webkul.
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.