API<21上的ListView嵌套滚动 [英] ListView nested scrolling on API&lt;21

本文介绍了API<21上的ListView嵌套滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题清晰.我有这个布局:

Title is clear. I'm having this layout:

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

工具栏和 tablayout 都在 AppBarLayout 内,所以我可以使用滚动标志来隐藏工具栏向顶部滚动.问题是这只适用于支持嵌套滚动的视图.大多数选项卡 - 我的意思是,大多数页面 - 都是 support.v4.NestedScrollViews,所以没问题;其他是(并且必须是)ListViews.

Both toolbar and tablayout are inside an AppBarLayout, so I can use scroll flags to hide the toolbar on scrolling toward the top. The problem is that this only works with nested-scrolling-supported views. Most of the tabs - I mean, most of the pages - are support.v4.NestedScrollViews, so that is OK; others are (and need to be) ListViews.

从 Lollipop 开始,我可以简单地将 android:nestedScrollingEnabled="true" 添加到列表视图中,工具栏会在滚动时正确隐藏.

From Lollipop on, I can simply add android:nestedScrollingEnabled="true" to the list view, and the toolbar hides correctly on scroll.

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

On API<21, though, there's no such attribute and the toolbar doesn't hide. Even more important, the very last items in the list are hidden, because of some measuring bug in CoordinatorLayout: listview acts as if it had the space currently occupied by the toolbar.

解决方案:

  • 切换到 RecyclerView,它确实支持嵌套滚动:我不能,因为我需要使用仅适用于适配器视图的外部库适配器,而我不能替换(即ParseQueryAdapter);

  • Switch to RecyclerView, which does support nested scrolling: I can't, because I need to use an external-library adapter that works only with adapter views and that I can't replace (namely, ParseQueryAdapter);

扩展ListView并实现嵌套滚动:似乎有点复杂;

Extend ListView and implement nested scrolling: seems way to complicated;

扩展 ListView 并实施一些解决方法,例如测量内容以避免最后一项问题或(和)使工具栏隐藏的自定义行为:似乎也很复杂;

Extend ListView and implement some workaround, like measuring stuff to avoid the last-item issue or (and) a custom behavior to make the toolbar hide: seems complicated too;

使用一些布局技巧:没有找到.

Use some layout trick: found none.

有什么帮助吗?

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

For example, I (desperately) tried:

<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.我得到了一个高度小的视图,页面的其余部分是空的.

But this way the ListView is not laid out as match_parent. I get a little view with small height, and the rest of the page is empty.

推荐答案

不幸的是,没有办法让嵌套滚动在 ListView 上工作 - 否则它不需要在API 21.

Unfortunately, there is no way to get nested scrolling working on ListView - otherwise it wouldn't require the modifications that were done in API 21.

您会注意到当前的 Parse SDK 实际上已经删除了 ParseQueryAdapter 完全.鉴于此,使用 RecyclerView 的适配器可能是有意义的>直接解析查询 API.

You'll note that the current 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.

这篇关于API<21上的ListView嵌套滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆