我正试图使用viewpager的滑动面板布局,就像这样

<?xml version="1.0" encoding="utf-8"?>

<android.support.v4.widget.SlidingPaneLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/scientific_graph_slidingPaneLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <!--
         The first child view becomes the left pane.
    -->

    <ListView
            android:id="@+id/left_pane"
            android:layout_width="240dp"
            android:layout_height="match_parent"
            android:layout_gravity="left" />
    <!--
         The second child becomes the right (content) pane.
    -->

    <android.support.v4.view.ViewPager
            android:id="@+id/scientific_graph_viewPager"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    </android.support.v4.view.ViewPager>

</android.support.v4.widget.SlidingPaneLayout>

当我从左边缘拉出时,滑动面板会滑动;但是,当我从右边缘拉出时,似乎无法使viewpager滑动。当我从右边拉的时候,它滑得很小,然后又弹回来。
这样做有可能吗?有更好的办法吗?
我发现通过向上和向左移动手指,我可以刷视图寻呼机。

最佳答案

根本原因是实现了IntercepttouchEvent。slidingpanelayout的一个旧实现调用了canscroll,它将检查触摸目标是否可以滚动,如果可以,将滚动触摸目标而不是滑动面板。最新的实现看起来总是截获运动事件,一旦阻力阈值超过坡度,除非x阻力超过坡度,y阻力超过x阻力(如op所述)。
解决这个问题的一个办法是复制slidingpanelayout并进行一些更改以使其工作。这些变化是:
修改intercepttouchevent中的action move case,同时选中canscroll,

if (adx > slop && ady > adx ||
    canScroll(this, false, Math.round(x - mInitialMotionX), Math.round(x), Math.round(y)))
{ ... }

修改最终签入可以滚动到“特殊情况”视图页。这种修改也可以通过重写canscroll在子类中完成,因为它不访问任何私有状态。
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
    ...
    /* special case ViewPagers, which don't properly implement the scrolling interface */
    return checkV && (ViewCompat.canScrollHorizontally(v, -dx) ||
        ((v instanceof ViewPager) && canViewPagerScrollHorizontally((ViewPager) v, -dx)))
}

boolean canViewPagerScrollHorizontally(ViewPager p, int dx) {
    return !(dx < 0 && p.getCurrentItem() <= 0 ||
        0 < dx && p.getAdapter().getCount() - 1 <= p.getCurrentItem());
}

修复viewdraghelper可能是一种更优雅的方法,但这是google在将来更新支持包时应该解决的问题。上面的技巧应该使布局与viewpagers(和其他水平滚动的容器?)一起工作。现在。

08-26 06:02