How to use Collapsing ToolBar with ListView instead of viewing Recycler

Does anyone know how to implement a minimize pane using Listview instead of recycler view?

+4
source share
2 answers

To do this, you must:

  • Deploy NestedScrollingChild in your custom ListView implementation.

  • Add a field private final NestedScrollingChildHelper mScrollingChildHelper;and initialize it in the constructors

  • Pass it methods from NestedScrollingChild

  • Call setNestedScrollingEnabled(true);after mScrollingChildHelperinitialization

Here is my implementation of a list view, 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);
    }
}
+4
source

.
Lollipop .

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        listView.setNestedScrollingEnabled(true);
        listView.startNestedScroll(View.OVER_SCROLL_ALWAYS);
    }
0

All Articles