Android画廊投掷

时间:2011-09-12 15:59:40

标签: android

我正在使用图库视图以全屏显示图像列表,当我滚动视图时,它滚动得如此之快。所以我重写了图库onTouch mentod

public boolean onTouch(View v, MotionEvent event) {
    switch(event.getAction()){
        case MotionEvent.ACTION_DOWN: {
            downX = event.getX();
            downY = event.getY();
            return true;
        }
        case MotionEvent.ACTION_UP: {
            upX = event.getX();
            upY = event.getY();

            float deltaX = downX - upX;
            float deltaY = downY - upY;

            // swipe horizontal?
            if(Math.abs(deltaX) > 100){
                // left or right
                if(deltaX < 0) { 

                    //this.onLeftToRightSwipe();
                    return true; 
                    }
                if(deltaX > 0) { 
                    Animation slideLeftOut = AnimationUtils.loadAnimation(this, R.anim.slide_left_out);
                    this.mGallery.startAnimation(slideLeftOut);
                    //this.onRightToLeftSwipe();
                    picPosition = picPosition + 1;
                    Animation slideLeftIn = AnimationUtils.loadAnimation(this, R.anim.slide_left_in);
                    this.mGallery.startAnimation(slideLeftIn);
                    mGallery.setSelection(picPosition, true);

                    return true;
                }
            }
        }
    }

    return false;
}

当我使用这个片段时,它的显示图像一个接一个但滚动看起来很奇怪。我不知道如何通过平滑滚动实现这一目标。我正在努力奋斗,任何人都可以帮忙...

1 个答案:

答案 0 :(得分:4)

尝试下面的代码,您基本上必须覆盖图库中的onFling()方法。

public class CustomGallery extends Gallery
{
    public CustomGallery(Context context, AttributeSet attrs) {
        super(context, attrs);  
    }

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