1. 程式人生 > 其它 >直播帶貨系統開發,介面滑動動畫的實現

直播帶貨系統開發,介面滑動動畫的實現

直播帶貨系統開發,介面滑動動畫的實現相關程式碼

float posX = 0, posY = 0, curPosX = 0, curPosY = 0;

imageView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()){
case MotionEvent.ACTION_DOWN:
posX = event.getX();
posY = event.getY();
break;
case MotionEvent.ACTION_MOVE: curPosX = event.getX(); curPosY = event.getY(); break; case MotionEvent.ACTION_UP: if ((curPosX - posX > 0) && (Math.abs(curPosX - posX) > 100)) { if (index > 0) { moveImage(--index); TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, -1.0f
, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f); animation.setRepeatMode(Animation.REVERSE); animation.setDuration(500); imageView.startAnimation(animation); } } else if ((curPosX - posX < 0) && (Math.abs(curPosX-posX) > 100)) { if (index < list_image.size() - 1
) { moveImage(++index); TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f); animation.setRepeatMode(Animation.REVERSE); animation.setDuration(500); imageView.startAnimation(animation); } } break; } return true; } });

以上就是 直播帶貨系統開發,介面滑動動畫的實現相關程式碼,更多內容歡迎關注之後的文章