private static void wrapperCoordinatorLayout(ViewGroup layout/*, final RefreshLayout refreshLayout*/, final CoordinatorLayoutListener listener) { for (int i = layout.getChildCount() - 1; i >= 0; i--) { View view = layout.getChildAt(i); if (view instanceof AppBarLayout) { ((AppBarLayout) view).addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { @Override public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { listener.onCoordinatorUpdate( verticalOffset >= 0, /*refreshLayout.isEnableLoadMore() && */ (appBarLayout.getTotalScrollRange() + verticalOffset) <= 0); } }); } } }
@Override public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { listener.onCoordinatorUpdate( verticalOffset >= 0, /*refreshLayout.isEnableLoadMore() && */ (appBarLayout.getTotalScrollRange() + verticalOffset) <= 0); } });
@Override public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { int visibility = View.VISIBLE; // 如果是AppbarLayout滑动到了最顶端,要把这个divider隐藏掉 if (getTablayout().getHeight() + toolbar.getHeight() - appBarLayout.getHeight() == verticalOffset) { visibility = View.GONE; } if (layHeaderDivider.getVisibility() != visibility) layHeaderDivider.setVisibility(visibility); }
private void shortPress(@Direction int direction) { if (mScrollable == null) { return; } switch (direction) { case DIRECTION_UP: if (!mScrollable.scrollToPrevious() && mAppBarEnabled && mAppBarLayout != null) { mAppBarLayout.setExpanded(true, true); } break; case DIRECTION_DOWN: if (mAppBarEnabled && mAppBarLayout != null && mAppBarLayout.getHeight() == mAppBarLayout.getBottom()) { mAppBarLayout.setExpanded(false, true); } else { mScrollable.scrollToNext(); } break; case DIRECTION_NONE: default: break; } }
public static void navigate(int direction, AppBarLayout appBarLayout, Navigable navigable) { switch (direction) { case Navigable.DIRECTION_DOWN: case Navigable.DIRECTION_RIGHT: if (appBarLayout.getBottom() == 0) { navigable.onNavigate(direction); } else { appBarLayout.setExpanded(false, true); } break; default: navigable.onNavigate(direction); break; } }
@Override public final void onOffsetChanged(AppBarLayout appBarLayout, int i) { if (i == 0) { if (mCurrentState != State.EXPANDED) { onStateChanged(appBarLayout, State.EXPANDED); } mCurrentState = State.EXPANDED; } else if (Math.abs(i) >= appBarLayout.getTotalScrollRange()) { if (mCurrentState != State.COLLAPSED) { onStateChanged(appBarLayout, State.COLLAPSED); } mCurrentState = State.COLLAPSED; } else { if (mCurrentState != State.IDLE) { onStateChanged(appBarLayout, State.IDLE); } mCurrentState = State.IDLE; } appBarLayout.addOnOffsetChangedListener(this); }
View mContentChild = mContentView.getChildAt(0); mContentChild.setFitsSystemWindows(false); ((View) appBarLayout.getParent()).setFitsSystemWindows(false); appBarLayout.setFitsSystemWindows(false); collapsingToolbarLayout.setFitsSystemWindows(false); collapsingToolbarLayout.getChildAt(0).setFitsSystemWindows(false); CoordinatorLayout.Behavior behavior = ((CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams()).getBehavior(); if (behavior != null && behavior instanceof AppBarLayout.Behavior) { int verticalOffset = ((AppBarLayout.Behavior) behavior).getTopAndBottomOffset(); if (Math.abs(verticalOffset) > appBarLayout.getHeight() - collapsingToolbarLayout.getScrimVisibleHeightTrigger()) { statusView.setAlpha(1f); } else { appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { private final static int EXPANDED = 0; private final static int COLLAPSED = 1;
@Override public void onPageSelected(int i) { /**不同的recyclerView的列表对应的位置不同,需要处理对应的顶部banner是否隐藏*/ curTab = i; scrollAppbar.removeOnOffsetChangedListener(MainActivity.this); int scrollHeight = (i == 0) ? scrollOffsetSquare : scrollOffsetAttention; if (scrollHeight == -scrollAppbar.getTotalScrollRange()) { CoordinatorLayout.Behavior behavior = ((CoordinatorLayout.LayoutParams) scrollAppbar.getLayoutParams()).getBehavior(); behavior.onNestedPreScroll(scrollCoordinatorLayout, scrollAppbar, fragmentList.get(i).getScrollableView(), 0, scrollAppbar.getTotalScrollRange(), new int[]{0, 0}); onOffsetChanged(scrollAppbar, scrollAppbar.getTotalScrollRange()); } scrollSwipeRefreshLayout.setEnabled(false); scrollAppbar.addOnOffsetChangedListener(MainActivity.this); }
private void refreshToTop1() { CoordinatorLayout.Behavior behavior = ((CoordinatorLayout.LayoutParams) scrollAppbar.getLayoutParams()).getBehavior(); behavior.onNestedPreScroll(scrollCoordinatorLayout, scrollAppbar, fragmentList.get(0).getScrollableView(), 0, scrollAppbar.getTotalScrollRange(), new int[]{0, 0}); onOffsetChanged(scrollAppbar, scrollAppbar.getTotalScrollRange()); fragmentList.get(0).changeToTop(); }
@Override protected void onAttachedToWindow() { super.onAttachedToWindow(); // Add an OnOffsetChangedListener if possible final ViewParent parent = getParent(); if (parent instanceof AppBarLayout) { ((AppBarLayout) parent).addOnOffsetChangedListener(innerOffsetChangedListener); layDetail = findViewById(R.id.layDetail); layRealDetail = findViewById(R.id.layRealDetail); toolbar = (Toolbar) findViewById(R.id.toolbar); appBarLayout = (AppBarLayout) parent; collapsingToolbarLayout = this; imgCover = (ImageView) findViewById(R.id.imgCover); tabLayout = (TabLayout) appBarLayout.findViewById(R.id.tabLayout); layName = findViewById(R.id.layName); } }
@Override public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { Log.e("zhouwei","appbarHeight:"+appBarLayout.getHeight()+" getTotalScrollRange:"+appBarLayout.getTotalScrollRange()+" offSet:"+verticalOffset); if(Math.abs(verticalOffset) >= appBarLayout.getTotalScrollRange()){ toolbar.setTitleTextColor(getResources().getColor(R.color.white)); collapsingToolbarLayout.setTitle("AppbarLayout"); }else{ collapsingToolbarLayout.setTitle(""); } } });
headerImage.setLayoutParams(lp); final int totalScrollRange = appBarLayout.getTotalScrollRange(); final float ratio = ((float)totalScrollRange + verticalOffset) / totalScrollRange; final int avatarRightest = appBarLayout.getMeasuredWidth() / 2 - avatarHalf - avatarHOffset; final int avatarTopest = avatarHalf + avatarVOffset;
@Override protected void onDetachedFromWindow() { if (mAppBar != null) { mAppBar.removeOnOffsetChangedListener(this); mAppBar = null; } super.onDetachedFromWindow(); }
@Override public void onTabReselected(TabLayout.Tab tab) { mAppBar.setExpanded(true, true); } });
private void initial(AppBarLayout abl) { this.mAppBarLayout = abl; abl.setClipChildren(false); mParentHeight = abl.getHeight(); }
private void hideAppBar() { ViewGroup.LayoutParams layoutParams = mAppBarLayout.getLayoutParams(); if (layoutParams.height == 0) return; layoutParams.height = 0; mAppBarLayout.setLayoutParams(layoutParams); }
/** * 绑定事件 */ private void initListener() { final CoAliRefreshBehavior myAppBarLayoutBehavoir = (CoAliRefreshBehavior) ((CoordinatorLayout.LayoutParams) mAppBarLayout.getLayoutParams()).getBehavior(); myAppBarLayoutBehavoir.setOnRefrehViewActionListener(new CoAliRefreshBehavior.onRefrehViewActionListener() { @Override public void onRefresh() { mSmileView.setDuration(2000); mSmileView.performAnim(); mSmileView.postDelayed(new Runnable() { @Override public void run() { Demo2Activity.this.runOnUiThread(new Runnable() { @Override public void run() { myAppBarLayoutBehavoir.stopPin(); mSmileView.cancelAnim(); } }); } }, 4000); } }); }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { switch (Item.values()[position % Item.values().length]) { case 折叠: mAppBarLayout.setExpanded(false, true); mAppBarLayout.setEnabled(false); mRecyclerView.setNestedScrollingEnabled(false); break; case 展开: mAppBarLayout.setEnabled(true); mAppBarLayout.setExpanded(true, true); mRecyclerView.setNestedScrollingEnabled(true); break; case 蓝色主题: setThemeColor(R.color.colorPrimary, R.color.colorPrimaryDark); break; case 绿色主题: setThemeColor(android.R.color.holo_green_light, android.R.color.holo_green_dark); break; case 红色主题: setThemeColor(android.R.color.holo_red_light, android.R.color.holo_red_dark); break; case 橙色主题: setThemeColor(android.R.color.holo_orange_light, android.R.color.holo_orange_dark); break; } mRefreshLayout.autoRefresh(); }
private void setUpToolbar() { mAppBarLayout.getLayoutParams().height = Utils.getDisplayMetrics(this).widthPixels * 9 / 16; mAppBarLayout.requestLayout(); setSupportActionBar(mToolBar); if (getSupportActionBar() != null) { getSupportActionBar().setDisplayShowTitleEnabled(false); getSupportActionBar().setDisplayHomeAsUpEnabled(true); } }