如何将折叠工具栏与ListView而不是Recycler View一起使用 [英] How to Use Collapsing ToolBar with a ListView instead of a Recycler View

查看:56
本文介绍了如何将折叠工具栏与ListView而不是Recycler View一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何使用列表视图而不是回收者视图来实现折叠工具栏吗?

Does anyone know how to implement the Collapsing Toolbar using A listview instead of a recycler view?

推荐答案

要使其生效,您应该:

  1. 在自定义ListView实现中实现NestedScrollingChild.

  1. Implement NestedScrollingChild in your custom ListView implementation.

添加字段 private final NestedScrollingChildHelper mScrollingChildHelper; 并将其在构造函​​数中初始化

Add field private final NestedScrollingChildHelper mScrollingChildHelper; and init it in constructors

从NestedScrollingChild中删除方法

Delegate to it methods from NestedScrollingChild

mScrollingChildHelper 初始化

以下是我的列表视图实现:

Here is my list view implementation for example:

public class NestedScrollingListView extends ListView implements NestedScrollingChild {

    private final NestedScrollingChildHelper mScrollingChildHelper;

    public NestedScrollingListView(Context context) {
       super(context);
       mScrollingChildHelper = new NestedScrollingChildHelper(this);
       setNestedScrollingEnabled(true);
    }

    public NestedScrollingListView(Context context, AttributeSet attrs) {
       super(context, attrs);
       mScrollingChildHelper = new NestedScrollingChildHelper(this);
       setNestedScrollingEnabled(true);
    }

    @Override
    public void setNestedScrollingEnabled(boolean enabled) {
       mScrollingChildHelper.setNestedScrollingEnabled(enabled);
    }

    @Override
    public boolean isNestedScrollingEnabled() {
       return mScrollingChildHelper.isNestedScrollingEnabled();
    }

    @Override
    public boolean startNestedScroll(int axes) {
       return mScrollingChildHelper.startNestedScroll(axes);
    }

    @Override
    public void stopNestedScroll() {
        mScrollingChildHelper.stopNestedScroll();
    }

    @Override
    public boolean hasNestedScrollingParent() {
        return mScrollingChildHelper.hasNestedScrollingParent();
    }

    @Override
    public boolean dispatchNestedScroll(int dxConsumed, int dyConsumed, int dxUnconsumed,
                                    int dyUnconsumed, int[] offsetInWindow) {
        return mScrollingChildHelper.dispatchNestedScroll(dxConsumed, dyConsumed,
            dxUnconsumed, dyUnconsumed, offsetInWindow);
    }

    @Override
    public boolean dispatchNestedPreScroll(int dx, int dy, int[] consumed, int[] offsetInWindow) {
        return mScrollingChildHelper.dispatchNestedPreScroll(dx, dy, consumed, offsetInWindow);
    }

    @Override
    public boolean dispatchNestedFling(float velocityX, float velocityY, boolean consumed) {
        return mScrollingChildHelper.dispatchNestedFling(velocityX, velocityY, consumed);
    }

    @Override
    public boolean dispatchNestedPreFling(float velocityX, float velocityY) {
        return mScrollingChildHelper.dispatchNestedPreFling(velocityX, velocityY);
    }
}

这篇关于如何将折叠工具栏与ListView而不是Recycler View一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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