Created
September 12, 2018 11:43
-
-
Save keinix/c8da6e20e855a5478885fbf69d5304c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int iconMargin = (itemView.getHeight() - icon.getIntrinsicHeight()) / 2; | |
int iconTop = itemView.getTop() + (itemView.getHeight() - icon.getIntrinsicHeight()) / 2; | |
int iconBottom = iconTop + icon.getIntrinsicHeight(); | |
if (dX > 0) { // Swiping to the right | |
int iconLeft = itemView.getLeft() + iconMargin + icon.getIntrinsicWidth(); | |
int iconRight = itemView.getLeft() + iconMargin; | |
icon.setBounds(iconLeft, iconTop, iconRight, iconBottom); | |
background.setBounds(itemView.getLeft(), itemView.getTop(), | |
itemView.getLeft() + ((int) dX) + backgroundCornerOffset, | |
itemView.getBottom()); | |
} else if (dX < 0) { // Swiping to the left | |
int iconLeft = itemView.getRight() - iconMargin - icon.getIntrinsicWidth(); | |
int iconRight = itemView.getRight() - iconMargin; | |
icon.setBounds(iconLeft, iconTop, iconRight, iconBottom); | |
background.setBounds(itemView.getRight() + ((int) dX) - backgroundCornerOffset, | |
itemView.getTop(), itemView.getRight(), itemView.getBottom()); | |
} else { // view is unSwiped | |
background.setBounds(0, 0, 0, 0); | |
} | |
background.draw(c); | |
icon.draw(c); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
icon.setBounds(0,0,0,0);
missing before or afterbackground.setBounds(0, 0, 0, 0);
at line 21the way you wrote it makes the icon visible after unswapping :) .