public void setGroupView(final ItemScrollFragment fragment, final int deltaPoster) { tivFanart .getViewTreeObserver() .addOnGlobalLayoutListener( new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { tivFanart.getViewTreeObserver().removeGlobalOnLayoutListener(this); int paddingTop = tivFanart.getHeight() - deltaPoster; DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); // if fanart take more than 1/2 of the screen, put the groupView on the fanart // halfway if (tivFanart.getHeight() > (metrics.heightPixels) / 2) paddingTop -= (tivFanart.getHeight() / 2); ViewGroup viewGroup = fragment.getGroupView(); fragment.setGroupViewPadding( viewGroup.getPaddingLeft(), paddingTop, viewGroup.getPaddingRight(), viewGroup.getPaddingBottom()); } }); }
public void onScrollChanged(ViewGroup viewGroup, int t) { int height = viewGroup.getPaddingTop(); // 0 when not translated // 1 when scrollView hit the top float percentTranslated = Utils.linearConversion(t, 0, height, 0, 1); // translate fanart tivFanart.setTranslationY(-t * 0.5f); // update fanart saturation cfh.update(tivFanart, 1 - percentTranslated); setActionBarAppearance(percentTranslated); }