直播带货系统开发,界面滑动动画的实现
直播带货系统开发,界面滑动动画的实现相关代码
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; } });
以上就是 直播带货系统开发,界面滑动动画的实现相关代码,更多内容欢迎关注之后的文章