Native Shopify Mobile App with 20 new features
Kickstart your hyperlocal marketplace in Corona pandemic with a starter guide
Android App Development
iOS 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 18.104.22.168 release ready!
Owner and Founder. Opencart
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.
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.