代码之家  ›  专栏  ›  技术社区  ›  d-man

android图像库开始移动或减速并停止移动

  •  3
  • d-man  · 技术社区  · 14 年前

    我正在使用android gallery,有没有什么方法可以让我知道当用户开始运动、停止运动、减速或移动时哪个会被炒鱿鱼?

    我看你能克服下列方法

    @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            return super.onFling(e1, e2, velocityX, velocityY);
        }
    

    但是我怎么知道滚动是要停止还是要开始呢?

    1 回复  |  直到 14 年前
        1
  •  0
  •   Jorgesys    14 年前

    你是在正确的方式,现在根据你的显示宽度,你将比较原始速度与修改后的速度。

    private float modifiedVelocityX;
    
    private void init() {
        Display display = ((WindowManager) getContext().getSystemService(
                Context.WINDOW_SERVICE)).getDefaultDisplay();
    int width = display.getWidth();
    int height = display.getHeight();
    Log.i(TAG, "Width = " + display.getWidth() + " Height = " + display.getHeight());
    modifiedVelocityX = (float) (width * 1.0); //*** 1.0 = Velocity Factor.
        }
    
    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
            float velocityY) {
            float mod = velocityX < 0 ? -modifiedVelocityX : modifiedVelocityX;
    if (getSelectedItemPosition() == 1 || getSelectedItemPosition() == getAdapter().getCount() - 2) {
                mod = velocityX < 0 ? -1 : 1;
            }
    
    Log.i(TAG, "Original Velocity X was " + velocityX + " now my Modified Velocity is " + mod);
        return super.onFling(e1, e2, mod, velocityY);
    }