ViewPager setCurrentItem(pageId, true) does NOT smoothscroll

前端 未结 13 1182
予麋鹿
予麋鹿 2020-12-02 13:01

I am compiling on SDK 4.03, Samsung Infuse Android 2.2, Support Library for Android 4, and using ViewPager in my app, actual swipe works fine, but when I do



        
13条回答
  •  长情又很酷
    2020-12-02 13:52

    This is what i did. I overrode the package-private method smoothScrollTo in ViewPager by putting my own custom subclass in the same package. It was being passed a value of zero, which causes the snapping behavior instead of the smooth scroll.

    package android.support.v4.view;
    
    import android.content.Context;
    import android.util.AttributeSet;
    
    public class MyViewPager extends ViewPager {
    
        public MyViewPager(Context context) {
            super(context);
        }
    
        public MyViewPager(Context context, AttributeSet attr) {
            super(context, attr);
        }
    
        void smoothScrollTo(int x, int y, int velocity) {
            super.smoothScrollTo(x, y, 1);
        }
    }
    

    It worked great, if you want you can calculate and provide actual velocity ISO of just 1.

提交回复
热议问题