我使用图库视图以全屏显示图像列表,当我滚动视图时,它滚动得如此之快。所以我覆盖了画廊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;
}


当我使用此代码段时,它的显示图像一个接一个,但滚动看起来很奇怪。我不知道如何通过平滑滚动来实现。我还在努力,请大家帮忙...

最佳答案

试试下面的代码,您基本上必须重写Gallery中的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);
    }
}

关于android - Android图库,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7390678/

10-09 16:00