@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); ButterKnife.bind(this, view); final CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) commentFrame.getLayoutParams(); commentFrame.setOnTouchListener( new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); behavior = (HideablePartBehavior) layoutParams.getBehavior(); behavior.setChangeCallback(this); root.setResizeCallback( new IgnorantCoordinatorLayout.ResizeCallback() { @Override public void onSizeChanged(int w, int h, int oldw, int oldh) { commentFrame.post( new Runnable() { @Override public void run() { behavior.sync(commentFrame); } }); } }); instrumentsLayout.removeAllViews(); LayoutInflater inflater = getLayoutInflater(savedInstanceState); for (final TextChanger changer : instruments) { View button = inflater.inflate(R.layout.include_instrument_button, instrumentsLayout, false); ((ImageView) button.findViewById(R.id.icon)).setImageResource(changer.getImageResource()); button.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { changer.onSelect(CommentEditFragment.this, text); selectedInstrument = instruments.indexOf(changer); } }); instrumentsLayout.addView(button); } }
public static void setDrag(boolean isDrag, AppBarLayout appBar) { final boolean drag = isDrag; ((CoordinatorLayout.LayoutParams) appBar.getLayoutParams()) .setBehavior(new AppBarLayout.Behavior() {}); CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) appBar.getLayoutParams(); AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) lp.getBehavior(); behavior.setDragCallback( new AppBarLayout.Behavior.DragCallback() { @Override public boolean canDrag(@NonNull AppBarLayout appBarLayout) { return drag; } }); }
public boolean onNestedFling(View target, float velocityX, float velocityY, boolean consumed) { ViewParent p = this.getParent().getParent(); if (p instanceof CoordinatorLayout) { CoordinatorLayout cl = ((CoordinatorLayout) p); AppBarLayout apl = (AppBarLayout) cl.findViewById(R.id.app_bar_layout); CoordinatorLayout.LayoutParams lp = (LayoutParams) apl.getLayoutParams(); final Behavior viewBehavior = lp.getBehavior(); if (viewBehavior != null) { viewBehavior.onNestedFling(this, apl, target, velocityX, velocityY, consumed); } } return super.onNestedFling(target, velocityX, velocityY, consumed); }
private void handleToolbarVisibility(final boolean show) { final AppBarLayout appBarLayout = (AppBarLayout) mToolbar.getParent(); final CoordinatorLayout rootLayout = (CoordinatorLayout) appBarLayout.getParent(); final CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams(); final AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior(); if (show) { // Show appBar behavior.setTopAndBottomOffset(0); behavior.onNestedPreScroll(rootLayout, appBarLayout, null, 0, 1, new int[2]); } else { // Hide appBar behavior.onNestedFling(rootLayout, appBarLayout, null, 0, 10000, true); } }