<i id='x4Zts'><tr id='x4Zts'><dt id='x4Zts'><q id='x4Zts'><span id='x4Zts'><b id='x4Zts'><form id='x4Zts'><ins id='x4Zts'></ins><ul id='x4Zts'></ul><sub id='x4Zts'></sub></form><legend id='x4Zts'></legend><bdo id='x4Zts'><pre id='x4Zts'><center id='x4Zts'></center></pre></bdo></b><th id='x4Zts'></th></span></q></dt></tr></i><div id='x4Zts'><tfoot id='x4Zts'></tfoot><dl id='x4Zts'><fieldset id='x4Zts'></fieldset></dl></div>
  • <small id='x4Zts'></small><noframes id='x4Zts'>

    • <bdo id='x4Zts'></bdo><ul id='x4Zts'></ul>

        <legend id='x4Zts'><style id='x4Zts'><dir id='x4Zts'><q id='x4Zts'></q></dir></style></legend>

        <tfoot id='x4Zts'></tfoot>

        平滑滚动在 ViewPager 中不起作用(支持库)

        时间:2023-10-04
        <tfoot id='Tr3sh'></tfoot>
          • <i id='Tr3sh'><tr id='Tr3sh'><dt id='Tr3sh'><q id='Tr3sh'><span id='Tr3sh'><b id='Tr3sh'><form id='Tr3sh'><ins id='Tr3sh'></ins><ul id='Tr3sh'></ul><sub id='Tr3sh'></sub></form><legend id='Tr3sh'></legend><bdo id='Tr3sh'><pre id='Tr3sh'><center id='Tr3sh'></center></pre></bdo></b><th id='Tr3sh'></th></span></q></dt></tr></i><div id='Tr3sh'><tfoot id='Tr3sh'></tfoot><dl id='Tr3sh'><fieldset id='Tr3sh'></fieldset></dl></div>

                <legend id='Tr3sh'><style id='Tr3sh'><dir id='Tr3sh'><q id='Tr3sh'></q></dir></style></legend>

                <small id='Tr3sh'></small><noframes id='Tr3sh'>

                • <bdo id='Tr3sh'></bdo><ul id='Tr3sh'></ul>
                    <tbody id='Tr3sh'></tbody>
                  本文介绍了平滑滚动在 ViewPager 中不起作用(支持库)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在编写使用 ViewPager 来托管 Fragments 的应用程序.

                  I am writing application that uses ViewPager to host Fragments.

                  当我以编程方式更改片段时,平滑滚动功能不起作用.我使用 ViewPager.setCurrentItem(int item, boolean smoothScroll)` 方法.

                  When I change fragment programmatically the smooth scroll function does not work. I use ViewPager.setCurrentItem(int item, boolean smoothScroll)` method.

                  也许有人知道解决此错误的方法吗?也许有动画?

                  Maybe anyone know a workaround this bug? Maybe with animations?

                  我正在使用支持包.问题是无论我使用 ViewPager.setCurrentItem(2, true) 还是 ViewPager.setCurrentItem(2, false) 结果都是一样的.视图切换非常快(不流畅).

                  I am using support package. And the issue is that whether I use ViewPager.setCurrentItem(2, true) or ViewPager.setCurrentItem(2, false) the result is the same. The view switches really fast (not smoothly).

                  推荐答案

                  我通过创建一个使用反射覆盖 ViewPager.mScroller 的 MyViewPager 解决了这个问题.

                  I've fixed this by creating a MyViewPager that overrides the ViewPager.mScroller using reflection.

                  public class MyViewPager extends ViewPager 
                  {
                    public MyViewPager( Context context, AttributeSet attrs) 
                    {
                      super( context, attrs );
                      setMyScroller();
                    }
                    private void setMyScroller() 
                    {
                      try 
                      {
                              Class<?> viewpager = ViewPager.class;
                              Field scroller = viewpager.getDeclaredField("mScroller");
                              scroller.setAccessible(true);
                              scroller.set(this, new MyScroller(getContext()));
                      } catch (Exception e) 
                      {
                          e.printStackTrace();
                      }
                    }
                  
                    public class MyScroller extends Scroller 
                    {
                      public MyScroller(Context context) 
                      {
                          super(context, new DecelerateInterpolator());
                      }
                  
                      @Override
                      public void startScroll(int startX, int startY, int dx, int dy, int duration) 
                      {
                          super.startScroll(startX, startY, dx, dy, 1000 /*1 secs*/);
                      }
                    }
                  } 
                  

                  这篇关于平滑滚动在 ViewPager 中不起作用(支持库)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:尝试在空对象引用上调用虚拟方法 'void android.support.v4.view.ViewPager. 下一篇:TabLayout 中的片段仅在用户滑动 Android 时加载

                  相关文章

                    1. <i id='VOj1S'><tr id='VOj1S'><dt id='VOj1S'><q id='VOj1S'><span id='VOj1S'><b id='VOj1S'><form id='VOj1S'><ins id='VOj1S'></ins><ul id='VOj1S'></ul><sub id='VOj1S'></sub></form><legend id='VOj1S'></legend><bdo id='VOj1S'><pre id='VOj1S'><center id='VOj1S'></center></pre></bdo></b><th id='VOj1S'></th></span></q></dt></tr></i><div id='VOj1S'><tfoot id='VOj1S'></tfoot><dl id='VOj1S'><fieldset id='VOj1S'></fieldset></dl></div>
                        <bdo id='VOj1S'></bdo><ul id='VOj1S'></ul>
                      <legend id='VOj1S'><style id='VOj1S'><dir id='VOj1S'><q id='VOj1S'></q></dir></style></legend>
                    2. <tfoot id='VOj1S'></tfoot>

                      <small id='VOj1S'></small><noframes id='VOj1S'>