@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); }
if (!onCoverSet && appBarLayout.getHeight() > 0) { onCoverSet = true; if (appbarHeight != appBarLayout.getHeight()) { appbarHeight = appBarLayout.getHeight(); maxVerticalOffset = appBarLayout.getHeight() - (statusbarHeight + toolbar.getHeight() + tabLayout.getHeight()) - 2; if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) { maxVerticalOffset = appBarLayout.getHeight() - (statusbarHeight + toolbar.getHeight() + tabLayout.getHeight()) - 2 - statusbarHeight;
@Override public void initListener() { mIbAddMenu.setOnClickListener(v -> { //显示或隐藏popupwindow View menuView = View.inflate(MainActivity.this, R.layout.menu_main, null); PopupWindow popupWindow = PopupWindowUtils.getPopupWindowAtLocation(menuView, getWindow().getDecorView(), Gravity.TOP | Gravity.RIGHT, UIUtils.dip2Px(5), mAppBar.getHeight() + 30); menuView.findViewById(R.id.tvCreateGroup).setOnClickListener(v1 -> { jumpToActivity(CreateGroupActivity.class); popupWindow.dismiss(); }); menuView.findViewById(R.id.tvHelpFeedback).setOnClickListener(v1 -> { jumpToWebViewActivity(AppConst.WeChatUrl.HELP_FEED_BACK); popupWindow.dismiss(); }); menuView.findViewById(R.id.tvAddFriend).setOnClickListener(v1 -> { jumpToActivity(AddFriendActivity.class); popupWindow.dismiss(); }); menuView.findViewById(R.id.tvScan).setOnClickListener(v1 -> { jumpToActivity(ScanActivity.class); popupWindow.dismiss(); }); }); mLlMessage.setOnClickListener(v -> bottomBtnClick(v)); mLlContacts.setOnClickListener(v -> bottomBtnClick(v)); mLlDiscovery.setOnClickListener(v -> bottomBtnClick(v)); mLlMe.setOnClickListener(v -> bottomBtnClick(v)); mVpContent.setOnPageChangeListener(this); }
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; } }
@Test public void testOnKeyUp() { KeyEvent keyEvent = mock(KeyEvent.class); when(keyEvent.getFlags()).thenReturn(KeyEvent.FLAG_CANCELED_LONG_PRESS); assertFalse(delegate.onKeyUp(KeyEvent.KEYCODE_BACK, keyEvent)); assertFalse(delegate.onKeyUp(KeyEvent.KEYCODE_VOLUME_UP, keyEvent)); assertFalse(delegate.onKeyUp(KeyEvent.KEYCODE_VOLUME_DOWN, keyEvent)); KeyEvent keyEventVolUp = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_VOLUME_UP), keyEventVolDown = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_VOLUME_DOWN); assertTrue(delegate.onKeyUp(KeyEvent.KEYCODE_VOLUME_UP, keyEventVolUp)); verify(scrollable).scrollToPrevious(); verify(appBar).setExpanded(eq(true), anyBoolean()); reset(scrollable, appBar); when(scrollable.scrollToPrevious()).thenReturn(true); assertTrue(delegate.onKeyUp(KeyEvent.KEYCODE_VOLUME_UP, keyEventVolUp)); verify(scrollable).scrollToPrevious(); verify(appBar, never()).setExpanded(eq(true), anyBoolean()); reset(scrollable, appBar); when(appBar.getHeight()).thenReturn(10); when(appBar.getBottom()).thenReturn(10); assertTrue(delegate.onKeyUp(KeyEvent.KEYCODE_VOLUME_DOWN, keyEventVolDown)); verify(scrollable, never()).scrollToNext(); verify(appBar).setExpanded(eq(false), anyBoolean()); reset(scrollable, appBar); when(appBar.getHeight()).thenReturn(10); when(appBar.getBottom()).thenReturn(0); assertTrue(delegate.onKeyUp(KeyEvent.KEYCODE_VOLUME_DOWN, keyEventVolDown)); verify(scrollable).scrollToNext(); verify(appBar, never()).setExpanded(eq(false), anyBoolean()); }
int maxOffset = appBarLayout.getHeight() - (getStatusBarHeight() + toolbar.getHeight() + tabLayout.getHeight());
@Override public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { if (Math.abs(verticalOffset) > appBarLayout.getHeight() - collapsingToolbarLayout.getScrimVisibleHeightTrigger()) { //toolbar被折叠时显示状态栏 if (statusView.getAlpha() == 0) { statusView.animate().cancel(); statusView.animate().alpha(1f).setDuration(collapsingToolbarLayout.getScrimAnimationDuration()).start(); } } else { //toolbar展开时显示状态栏 if (statusView.getAlpha() == 1) { statusView.animate().cancel(); statusView.animate().alpha(0f).setDuration(collapsingToolbarLayout.getScrimAnimationDuration()).start(); } } } });
@Override public void run() { mAppBarHeight = mAppBarLayout.getHeight(); } });
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 {
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 {
private void initial(AppBarLayout abl) { this.mAppBarLayout = abl; abl.setClipChildren(false); mParentHeight = abl.getHeight(); }
private void initial(AppBarLayout abl) { abl.setClipChildren(false); mParentHeight = abl.getHeight(); mTargetViewHeight = mTargetView.getHeight(); Log.e(TAG, "initial: mParentHeight==" + mParentHeight); Log.e(TAG, "initial: mTargetViewHeight==" + mTargetViewHeight); // mMiddleHeight = middleLayout.getHeight(); }
protected void hideOrShowToolbar() { mAppBar.animate() .translationY(mIsHidden ? 0 : -mAppBar.getHeight()) .setInterpolator(new DecelerateInterpolator(2)) .start(); mIsHidden = !mIsHidden; } }
private void initial(AppBarLayout abl) { abl.setClipChildren(false); mParentHeight = abl.getHeight(); mTargetViewHeight = mTargetView.getHeight(); mMiddleHeight = middleLayout.getHeight(); }
@Override public void check(View view, NoMatchingViewException noViewFoundException) { AppBarLayout appBarLayout = (AppBarLayout) view; boolean isFullExpanded = appBarLayout.getHeight() - appBarLayout.getBottom() == 0; ViewMatchers.assertThat("is full expanded", isFullExpanded, is(true)); } };
private void calculateValues() { collapsedHeight = toolbar.getHeight(); expandedHeight = appBarLayout.getHeight() - toolbar.getHeight(); maxOffset = expandedHeight; }
private void calculateValues() { collapsedHeight = toolbar.getHeight(); expandedHeight = appBarLayout.getHeight() - toolbar.getHeight(); maxOffset = expandedHeight; }
@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(""); } } });
@Override public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { show(true); MarginLayoutParams layoutParams = (MarginLayoutParams) getLayoutParams(); layoutParams.topMargin = mAppBarLayout.getHeight() + verticalOffset; //AppBarLayout actual height mAppBarLayoutOffset = -verticalOffset; setLayoutParams(layoutParams); } });
public void hideOrShowToolbar() { getView().getAppBarLaytout().animate() .translationY(mIsHidden ? 0 : -getView().getAppBarLaytout().getHeight()) .setInterpolator(new DecelerateInterpolator(2)) .start(); mIsHidden = !mIsHidden; }