Search in sources :

Example 1 with AppBarStateChangeListener

use of com.d.lib.xrv.listener.AppBarStateChangeListener in project xRecyclerViewF by Dsiner.

the class XRecyclerView method onAttachedToWindow.

@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    //解决和CollapsingToolbarLayout冲突的问题
    AppBarLayout appBarLayout = null;
    ViewParent p = getParent();
    while (p != null) {
        if (p instanceof CoordinatorLayout) {
            break;
        }
        p = p.getParent();
    }
    if (p instanceof CoordinatorLayout) {
        CoordinatorLayout coordinatorLayout = (CoordinatorLayout) p;
        final int childCount = coordinatorLayout.getChildCount();
        for (int i = childCount - 1; i >= 0; i--) {
            final View child = coordinatorLayout.getChildAt(i);
            if (child instanceof AppBarLayout) {
                appBarLayout = (AppBarLayout) child;
                break;
            }
        }
        if (appBarLayout != null) {
            appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() {

                @Override
                public void onStateChanged(AppBarLayout appBarLayout, State state) {
                    appbarState = state;
                }
            });
        }
    }
}
Also used : CoordinatorLayout(android.support.design.widget.CoordinatorLayout) AppBarStateChangeListener(com.d.lib.xrv.listener.AppBarStateChangeListener) ViewParent(android.view.ViewParent) ListState(com.d.lib.xrv.view.ListState) AppBarLayout(android.support.design.widget.AppBarLayout) IRecyclerView(com.d.lib.xrv.listener.IRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Aggregations

AppBarLayout (android.support.design.widget.AppBarLayout)1 CoordinatorLayout (android.support.design.widget.CoordinatorLayout)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 ViewParent (android.view.ViewParent)1 AppBarStateChangeListener (com.d.lib.xrv.listener.AppBarStateChangeListener)1 IRecyclerView (com.d.lib.xrv.listener.IRecyclerView)1 ListState (com.d.lib.xrv.view.ListState)1