Search in sources :

Example 1 with AppBarStateChangeListener

use of org.yh.library.view.yhrecyclerview.AppBarStateChangeListener in project YhLibraryForAndroid by android-coco.

the class YHRecyclerView 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(org.yh.library.view.yhrecyclerview.AppBarStateChangeListener) ViewParent(android.view.ViewParent) AppBarLayout(android.support.design.widget.AppBarLayout) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) Paint(android.graphics.Paint)

Aggregations

Paint (android.graphics.Paint)1 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 (org.yh.library.view.yhrecyclerview.AppBarStateChangeListener)1