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

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

        <legend id='L8E2X'><style id='L8E2X'><dir id='L8E2X'><q id='L8E2X'></q></dir></style></legend>
        • <bdo id='L8E2X'></bdo><ul id='L8E2X'></ul>

      1. <tfoot id='L8E2X'></tfoot>

        Android ViewPager with ScrollViews with ViewPagers inside th

        时间:2023-10-04

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

          <tfoot id='RX2Sg'></tfoot>
        • <legend id='RX2Sg'><style id='RX2Sg'><dir id='RX2Sg'><q id='RX2Sg'></q></dir></style></legend>

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

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

                  问题描述

                  所以我的 Activity 有一个主 ViewPager,在 ViewPager 内部每个页面都有一个 ScrollView 的全部内容,并且在该 ScrollView 内部还有另一个 ViewPager.

                  So I have my activity which has a main ViewPager and inside of the ViewPager each page has the whole content as a ScrollView and inside of that ScrollView there is another ViewPager.

                  这听起来可能很疯狂,但基本上外部 ViewPager 包含新闻文章,并且文章很长,因此有一个 ScrollView,并且在 ScrollView 内部有多个缩略图/图片,它们也可以滑动浏览.

                  This might sound crazy but basically the outer ViewPager contains news articles, and the articles are long so there is a ScrollView, and inside the ScrollView there are multiple thumbnails/pictures that they can swipe through as well.

                  我尝试了几种不同的自定义 ViewPager,它们具有不同的触摸事件拦截功能,但似乎无法做到完美.它要么完全吸收所有触摸事件,因此 ScrollView 的垂直滚动在该区域不起作用,要么让内部的水平滚动非常敏感/困难.

                  I've tried a few different custom ViewPagers with different touch event interception but can't seem to get it perfect. It either completely will absorb all touch events so that the vertical scrolling of the ScrollView doesn't work in that area, or it will be really touchy/difficult to get the inner one to scroll horizontally.

                  谁有完美的解决方案?

                  推荐答案

                  如果有人想知道我的解决方案:

                  In case anyone wants to know my solution:

                  public class CustomScrollView extends ScrollView {
                  private GestureDetector mGestureDetector;
                  View.OnTouchListener mGestureListener;
                  
                  public CustomScrollView(Context context, AttributeSet attrs) {
                      super(context, attrs);
                      mGestureDetector = new GestureDetector(context, new YScrollDetector());
                      setFadingEdgeLength(0);
                  }
                  
                  @Override
                  public boolean onInterceptTouchEvent(MotionEvent ev) {
                      return super.onInterceptTouchEvent(ev)
                              && mGestureDetector.onTouchEvent(ev);
                  }
                  
                  // Return false if we're scrolling in the x direction
                  class YScrollDetector extends SimpleOnGestureListener {
                      @Override
                      public boolean onScroll(MotionEvent e1, MotionEvent e2,
                              float distanceX, float distanceY) {
                          if (Math.abs(distanceY) > Math.abs(distanceX)) {
                              return true;
                          }
                          return false;
                      }
                  }
                  }
                  

                  最外面的ViewPager是:

                  and the outer most ViewPager is:

                  public class NestingViewPager extends ViewPager {
                  
                  public NestingViewPager(final Context context, final AttributeSet attrs) {
                      super(context, attrs);
                  }
                  
                  public NestingViewPager(final Context context) {
                      super(context);
                  }
                  
                  @Override
                  protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
                      if (v != this && v instanceof ViewPager) {
                          return true;
                      }
                      return super.canScroll(v, checkV, dx, x, y);
                  }
                  }
                  

                  这篇关于Android ViewPager with ScrollViews with ViewPagers inside the ScrollViews的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:更改 viewPager 滑动方向 下一篇:ViewPager 的无尽适配器

                  相关文章

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

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

                        <bdo id='dNT26'></bdo><ul id='dNT26'></ul>
                      <tfoot id='dNT26'></tfoot>