Skip to content

Instantly share code, notes, and snippets.

@keinix
Created September 12, 2018 11:43
Show Gist options
  • Save keinix/c8da6e20e855a5478885fbf69d5304c7 to your computer and use it in GitHub Desktop.
Save keinix/c8da6e20e855a5478885fbf69d5304c7 to your computer and use it in GitHub Desktop.
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);
@samerbahri98
Copy link

icon.setBounds(0,0,0,0); missing before or after background.setBounds(0, 0, 0, 0); at line 21

the way you wrote it makes the icon visible after unswapping :) .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment