Created
October 24, 2015 16:54
-
-
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:
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
@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