Skip to content

Instantly share code, notes, and snippets.

@ahmedlhanafy
Created October 24, 2015 16:54
Show Gist options
  • Save ahmedlhanafy/d1aae2512866f6b2e89e to your computer and use it in GitHub Desktop.
Save ahmedlhanafy/d1aae2512866f6b2e89e to your computer and use it in GitHub Desktop.
The Design Support Library includes some great pre-built CoordinatorLayout Behaviors for free, like the SwypeToDismissBehavior<T> which is really easy to implement:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_swipe_behavior);
mCardView = (CardView) findViewById(R.id.swype_card);
final SwipeDismissBehavior<CardView>
swipe = new SwipeDismissBehavior();
swipe.setSwipeDirection(
SwipeDismissBehavior.SWIPE_DIRECTION_ANY);
swipe.setListener(
new SwipeDismissBehavior.OnDismissListener() {
@Override
public void onDismiss(View view) {
Toast.makeText(Activity.this,
"Card swiped !!", Toast.LENGTH_SHORT).show();
}
);
LayoutParams coordinatorParams =
(LayoutParams) mCardView.getLayoutParams();
coordinatorParams.setBehavior(swipe);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment