ViewPager setCurrentItem(pageId, true) does NOT smoothscroll

前端 未结 13 1112
予麋鹿
予麋鹿 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:54

    For those who use Xamarin (albeit this approach is applicable to Java as well) I can suggest to use the next approach based on the answer above (ViewPager from Android Support Library v7 AppCompat 19.1.0):

    public void ScrollSmooth(int i)
    {
        var jClass = JNIEnv.GetObjectClass(_pager.Handle);
        var jMethod = JNIEnv.GetMethodID(jClass, "setCurrentItemInternal", "(IZZI)V");
        JNIEnv.CallVoidMethod (_pager.Handle, jMethod, new JValue (i), new JValue (true), new JValue (false), new JValue (1));
    }
    

    It relies on ViewPager implementation from http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.1_r1/android/support/v4/view/ViewPager.java

    0 讨论(0)
提交回复
热议问题