API<21 上的 ListView 嵌套滚动

ListView nested scrolling on API<21

标题很清楚。我有这个布局:

_________________
|_______________| <- Toolbar    
|___|___|___|___| <- Tablayout
|               |
|               |
|   ViewPager   |
|               |
|_______________|

工具栏和 tablayout 都在 AppBarLayout 内,因此我可以使用滚动标志在向顶部滚动时隐藏工具栏。问题是这仅适用于 nested-scrolling-supported 视图。大多数选项卡 - 我的意思是,大多数页面 - 都是 support.v4.NestedScrollViews,所以没关系;其他人是(并且需要)ListViews.

从 Lollipop 开始,我只需将 android:nestedScrollingEnabled="true" 添加到列表视图,工具栏就会在滚动时正确隐藏。

在 API<21 上,没有这样的属性,工具栏也不会隐藏。更重要的是,列表中的最后一项被隐藏了,因为 CoordinatorLayout 中的一些测量错误:listview 就好像它有 space 当前被工具栏占用一样。

解决方案:

有什么帮助吗?

例如,我(拼命地)尝试过:

<android.support.v4.widget.NestedScrollView
    android:nestedScrollingEnabled="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </ListView>

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

但是这样 ListView 就不会像 match_parent 那样排列了。我得到了一个小高度的小视图,页面的其余部分是空的。

不幸的是,无法在 ListView 上使用嵌套滚动 - 否则它不需要在 API 21.

中完成的修改

您会注意到当前 Parse SDK has actually removed ParseQueryAdapter entirely. Given that, it may make sense to start building your own RecyclerView based adapter using the Parse query APIs directly

对于那些对特定 ParseQueryAdapter 问题感兴趣的人,

我实际上是一名 Xamarin 开发人员,所以我无法测试这是否适用于这种特殊情况,但我发现 an answer which helped me in Xamarin,所以我要分享它:

I found a solution that works excellently and can scroll the ListView without problems:

ListView lv = (ListView)findViewById(R.id.myListView);  // your
listview inside scrollview lv.setOnTouchListener(new
ListView.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        int action = event.getAction();
        switch (action) {
        case MotionEvent.ACTION_DOWN:
            // Disallow ScrollView to intercept touch events.
            v.getParent().requestDisallowInterceptTouchEvent(true);
            break;

        case MotionEvent.ACTION_UP:
            // Allow ScrollView to intercept touch events.
            v.getParent().requestDisallowInterceptTouchEvent(false);
            break;
        }

        // Handle ListView touch events.
        v.onTouchEvent(event);
        return true;
    }
});

What this does is disable the TouchEvents on the ScrollView and make the ListView intercept them. It is simple and works all the time.

如果这不起作用,请告诉我,以便我删除此答案。但也许它对任何人都有帮助,因为我也发现了这个问题,但似乎没有解决方案。