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

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

  • <tfoot id='UrNWO'></tfoot>

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

        一侧 ViewPager 仅滑动

        时间:2023-10-04

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

        <tfoot id='huIGh'></tfoot>
            • <bdo id='huIGh'></bdo><ul id='huIGh'></ul>

                  <tbody id='huIGh'></tbody>

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

                  本文介绍了一侧 ViewPager 仅滑动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我的应用程序中有一个 ViewPager,我想随时禁用/允许向右滑动.viewpager 中的每个视图都包含 ListView.我怎样才能做到这一点?我正在尝试以这种方式做到这一点:

                  I have a ViewPager in my application and I would like to disable/allow swipe to right side in any time. Every view in the viewpager contains ListView. How can I do that? I am trying to do that in this way:

                  private int oldX;
                  private int deltaX = 0;
                  
                  @Override
                  public boolean onTouch(View view, MotionEvent motionEvent) {
                      if (motionEvent.getAction() == MotionEvent.ACTION_MOVE || motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
                          int newX = (int) motionEvent.getX();
                          deltaX = oldX - newX;
                          oldX = newX;
                      }
                      if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
                          oldX = 0;
                      }
                      return deltaX < 0;        
                  }
                  

                  但是视图仍然会向右一点.有人在解决同样的问题吗?

                  But view is still going to right side a little bit. Anyone was solving the same issue?

                  推荐答案

                  通过将 ViewPager 的代码放入我的应用程序并添加以下内容,我能够在 ViewPager 中实现单侧滚动

                  I was able to achieve one-side scrolling in ViewPager by taking its code to my application and adding the following

                  private boolean performDrag(float x) {
                      boolean needsInvalidate = false;
                  
                      final float deltaX = mLastMotionX - x;
                      mLastMotionX = x;
                  
                      // MY CODE STARTS
                      if (deltaX < 0) {
                          return false;
                      }
                      // MY CODE ENDS
                  
                      float oldScrollX = getScrollX();
                      ...
                  

                  它似乎工作正常.您可能需要的唯一东西 - 获取适配器代码或提供您自己的适配器,因为 ViewPager 在其代码中使用的某些方法不是从 PagerAdapter 公开的.

                  It seems to work fine. The only thing You might need - take adapter code or provide Your own adapter, because some methods ViewPager uses in its code are not public from PagerAdapter.

                  这篇关于一侧 ViewPager 仅滑动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在带有 android 的视图寻呼机页面中使用滑动手势? 下一篇:Android 中的 Viewpager 可以无休止地在几天之间切换

                  相关文章

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

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

                4. <legend id='h4Uph'><style id='h4Uph'><dir id='h4Uph'><q id='h4Uph'></q></dir></style></legend>

                  1. <small id='h4Uph'></small><noframes id='h4Uph'>