import com.nineoldandroids.view.ViewHelper; //导入方法依赖的package包/类
/**
* Moves the view
*
* @param deltaX delta
*/
public void move(float deltaX) {
swipeListView.onMove(downPosition, deltaX);
float posX = ViewHelper.getX(frontView);
if (opened.get(downPosition)) {
posX += openedRight.get(downPosition) ? -viewWidth + rightOffset : viewWidth - leftOffset;
}
if (posX > 0 && !swipingRight) {
Log.d("SwipeListView", "change to right");
swipingRight = !swipingRight;
swipeCurrentAction = swipeActionRight;
if (swipeCurrentAction == SwipeListView.SWIPE_ACTION_CHOICE) {
backView.setVisibility(View.GONE);
} else {
backView.setVisibility(View.VISIBLE);
}
}
if (posX < 0 && swipingRight) {
Log.d("SwipeListView", "change to left");
swipingRight = !swipingRight;
swipeCurrentAction = swipeActionLeft;
if (swipeCurrentAction == SwipeListView.SWIPE_ACTION_CHOICE) {
backView.setVisibility(View.GONE);
} else {
backView.setVisibility(View.VISIBLE);
}
}
if (swipeCurrentAction == SwipeListView.SWIPE_ACTION_DISMISS) {
setTranslationX(parentView, deltaX);
setAlpha(parentView, Math.max(0f, Math.min(1f,
1f - 2f * Math.abs(deltaX) / viewWidth)));
} else if (swipeCurrentAction == SwipeListView.SWIPE_ACTION_CHOICE) {
if ((swipingRight && deltaX > 0 && posX < DISPLACE_CHOICE)
|| (!swipingRight && deltaX < 0 && posX > -DISPLACE_CHOICE)
|| (swipingRight && deltaX < DISPLACE_CHOICE)
|| (!swipingRight && deltaX > -DISPLACE_CHOICE)) {
setTranslationX(frontView, deltaX);
}
} else {
setTranslationX(frontView, deltaX);
}
}