@Override public void onAnimationEnd(View view) { draggableView.setOverlayLeftAlpha(0f); draggableView.setOverlayRightAlpha(0f); } })
public void setOverlayLayouts(int layoutLeftResId, int layoutRightResId) { if (layoutLeftResId != 0) { this.layoutLeftResId = layoutLeftResId; if (overlayLeft != null) { overlay.removeView(overlayLeft); } overlayLeft = LayoutInflater.from(getContext()).inflate(this.layoutLeftResId, overlay, false); if (overlayLeft != null) { overlay.addView(overlayLeft); setOverlayLeftAlpha(0f); } } if (layoutRightResId != 0) { this.layoutRightResId = layoutRightResId; if (overlayRight != null) { overlay.removeView(overlayRight); } overlayRight = LayoutInflater.from(getContext()).inflate(this.layoutRightResId, overlay, false); if (overlayRight != null) { overlay.addView(overlayRight); setOverlayRightAlpha(0f); } } }
@Override public void update(CardDraggableView draggableView, float percentX, float percentY) { super.update(draggableView, percentX, percentY); if (percentX < 0) { if (draggableView.getOldPercentX() >= 0) { //percent changed sign draggableView.getOverlayView().setBackgroundColor(draggableView.getColorLeft()); draggableView.setOverlayLeftAlpha(1f); draggableView.setOverlayRightAlpha(0f); } } else { if (draggableView.getOldPercentX() <= 0) { //percent changed sign draggableView.getOverlayView().setBackgroundColor(draggableView.getColorRight()); draggableView.setOverlayLeftAlpha(0f); draggableView.setOverlayRightAlpha(1f); } } ViewCompat.setAlpha(draggableView.getOverlayView(), Math.abs(percentX)); }
@Override public void update(CardDraggableView draggableViewFront, float percentX, float percentY) { CardDraggableView draggableViewBottom = shuffle.getDraggableView(1); if (percentX <= 0) { draggableViewBottom.setOverlayLeftAlpha(1f); draggableViewBottom.setOverlayRightAlpha(0f); } else { draggableViewBottom.setOverlayLeftAlpha(0f); draggableViewBottom.setOverlayRightAlpha(1f); } float percent = Math.abs(percentX); percent = (float) Math.pow(percent, 10); percent = Math.min(0.09f, percent); if(percent == 0f){ ViewCompat.setAlpha(draggableViewBottom.getOverlayView(), 0f); ViewCompat.animate(draggableViewBottom.getContent()).withLayer().setDuration(100).alpha(1f); } else { ViewCompat.animate(draggableViewBottom.getContent()).cancel(); ViewCompat.setAlpha(draggableViewBottom.getContent(), percent); ViewCompat.setAlpha(draggableViewBottom.getOverlayView(), 1f); } } }