I'm trying to make a moving card.

XML

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="fill_parent" android:id="@+id/cvsdclayout" android:layout_height="fill_parent" android:orientation="vertical"> 

 <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" android:id="@+id/card_view" android:layout_width="match_parent" android:layout_height="300dp" card_view:cardUseCompatPadding="true" card_view:cardCornerRadius="5dp" card_view:cardElevation="5dp" card_view:cardBackgroundColor="#ffffff" android:layout_margin="20dp"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/info_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Swipe me..." android:layout_centerInParent="true" android:textSize="18sp" android:textColor="#000000"/> </RelativeLayout> </android.support.v7.widget.CardView> </android.support.design.widget.CoordinatorLayout> 

Java

 CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) card.getLayoutParams(); final SwipeDismissBehavior<CardView> behavior = new SwipeDismissBehavior<CardView>(); behavior.setSwipeDirection(SwipeDismissBehavior.SWIPE_DIRECTION_ANY); behavior.setListener(new SwipeDismissBehavior.OnDismissListener() { @Override public void onDismiss(final View view) { Snackbar.make(coordinatorLayout, "Done", Snackbar.LENGTH_LONG) .show(); } @Override public void onDragStateChanged(int i) { } }); params.setBehavior(behavior); card.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return behavior.onTouchEvent((CoordinatorLayout) coordinatorLayout, card, event); } }); 

When shifted to the right, CardView “rattles,” dangles sharply from side to side, and disappears abruptly in the case of an incomplete shift. When shifting to the left, it more or less quietly shifts, but with full shift it appears again in its place ...

    0