@Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

    int height = MeasureSpec.getSize(heightMeasureSpec);
    int width = MeasureSpec.getSize(widthMeasureSpec);

    int heightMode = MeasureSpec.getMode(heightMeasureSpec);

    final View child = getChildAt(0);
    if (child == null) {
      setMeasuredDimension(0, width);
      return;
    }

    if (child.isLayoutRequested()) {
      // Always let child be as tall as it wants.
      measureChild(
          child, widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    }

    if (heightMode == MeasureSpec.UNSPECIFIED) {
      ViewGroup.LayoutParams lp = getLayoutParams();

      if (lp.height > 0) {
        height = lp.height;
      } else {
        height = child.getMeasuredHeight();
      }
    }

    setMeasuredDimension(width, height);
  }
 void a(View paramView, boolean paramBoolean, Rect paramRect)
 {
   if ((paramView.isLayoutRequested()) || (paramView.getVisibility() == 8))
   {
     paramRect.set(0, 0, 0, 0);
     return;
   }
   if (paramBoolean)
   {
     a(paramView, paramRect);
     return;
   }
   paramRect.set(paramView.getLeft(), paramView.getTop(), paramView.getRight(), paramView.getBottom());
 }
  private void ensurePinnedHeaderLayout(View header) {
    if (header.isLayoutRequested()) {
      int widthSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth(), mWidthMode);

      int heightSpec;
      ViewGroup.LayoutParams layoutParams = header.getLayoutParams();
      if (layoutParams != null && layoutParams.height > 0) {
        heightSpec = MeasureSpec.makeMeasureSpec(layoutParams.height, MeasureSpec.EXACTLY);
      } else {
        heightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
      }
      header.measure(widthSpec, heightSpec);
      header.layout(0, 0, header.getMeasuredWidth(), header.getMeasuredHeight());
    }
  }
  private void prepareContent() {
    if (mAnimating) {
      return;
    }

    // Something changed in the content, we need to honor the layout request
    // before creating the cached bitmap
    final View content = mContent;
    if (content.isLayoutRequested()) {
      if (mVertical) {
        final int childHeight = mHandleHeight;
        int height = mBottom - mTop - childHeight - mTopOffset;
        content.measure(
            MeasureSpec.makeMeasureSpec(mRight - mLeft, MeasureSpec.EXACTLY),
            MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
        content.layout(
            0,
            mTopOffset + childHeight,
            content.getMeasuredWidth(),
            mTopOffset + childHeight + content.getMeasuredHeight());
      } else {
        final int childWidth = mHandle.getWidth();
        int width = mRight - mLeft - childWidth - mTopOffset;
        content.measure(
            MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
            MeasureSpec.makeMeasureSpec(mBottom - mTop, MeasureSpec.EXACTLY));
        content.layout(
            childWidth + mTopOffset,
            0,
            mTopOffset + childWidth + content.getMeasuredWidth(),
            content.getMeasuredHeight());
      }
    }
    // Try only once... we should really loop but it's not a big deal
    // if the draw was cancelled, it will only be temporary anyway
    content.getViewTreeObserver().dispatchOnPreDraw();
    content.buildDrawingCache();

    content.setVisibility(View.GONE);
  }
  private void makeAndAddView(View child) {

    FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) child.getLayoutParams();
    //		FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(350,500);
    if (lp == null) {
      lp =
          new FrameLayout.LayoutParams(
              ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    }
    addViewInLayout(child, 0, lp, true);

    final boolean needToMeasure = child.isLayoutRequested();
    if (needToMeasure) {
      try {
        int childWidthSpec =
            getChildMeasureSpec(
                getWidthMeasureSpec(),
                getPaddingLeft() + getPaddingRight() + lp.leftMargin + lp.rightMargin,
                lp.width);
        int childHeightSpec =
            getChildMeasureSpec(
                getHeightMeasureSpec(),
                getPaddingTop() + getPaddingBottom() + lp.topMargin + lp.bottomMargin,
                lp.height);
        System.out.println(
            childWidthSpec + " childWidthSpec " + childHeightSpec + " childHeightSpec");
        child.measure(childWidthSpec, childHeightSpec);
      } catch (Exception e) {
        e.printStackTrace();
      }
    } else {
      cleanupLayoutState(child);
    }

    int w = child.getMeasuredWidth();
    int h = child.getMeasuredHeight();

    int gravity = lp.gravity;
    if (gravity == -1) {
      gravity = Gravity.TOP | Gravity.START;
    }

    //        int layoutDirection = getLayoutDirection();
    int layoutDirection = 1;
    //        final int absoluteGravity = Gravity.getAbsoluteGravity(gravity, layoutDirection);
    final int absoluteGravity = gravity;
    final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;

    int childLeft;
    int childTop;
    switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
      case Gravity.CENTER_HORIZONTAL:
        childLeft =
            (getWidth() + getPaddingLeft() - getPaddingRight() - w) / 2
                + lp.leftMargin
                - lp.rightMargin;
        break;
      case Gravity.END:
        childLeft = getWidth() + getPaddingRight() - w - lp.rightMargin;
        break;
      case Gravity.START:
      default:
        childLeft = getPaddingLeft() + lp.leftMargin;
        break;
    }
    switch (verticalGravity) {
      case Gravity.CENTER_VERTICAL:
        childTop =
            (getHeight() + getPaddingTop() - getPaddingBottom() - h) / 2
                + lp.topMargin
                - lp.bottomMargin;
        break;
      case Gravity.BOTTOM:
        childTop = getHeight() - getPaddingBottom() - h - lp.bottomMargin;
        break;
      case Gravity.TOP:
      default:
        childTop = getPaddingTop() + lp.topMargin;
        break;
    }

    child.layout(childLeft, childTop, childLeft + w, childTop + h);
  }
  @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
  private void makeAndAddView(View child) {

    FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) child.getLayoutParams();
    addViewInLayout(child, 0, lp, true);

    final boolean needToMeasure = child.isLayoutRequested();
    if (needToMeasure) {
      int childWidthSpec =
          getChildMeasureSpec(
              getWidthMeasureSpec(),
              getPaddingLeft() + getPaddingRight() + lp.leftMargin + lp.rightMargin,
              lp.width);
      int childHeightSpec =
          getChildMeasureSpec(
              getHeightMeasureSpec(),
              getPaddingTop() + getPaddingBottom() + lp.topMargin + lp.bottomMargin,
              lp.height);
      child.measure(childWidthSpec, childHeightSpec);
    } else {
      cleanupLayoutState(child);
    }

    int w = child.getMeasuredWidth();
    int h = child.getMeasuredHeight();

    int gravity = lp.gravity;
    if (gravity == -1) {
      gravity = Gravity.TOP | Gravity.START;
    }

    int layoutDirection = getLayoutDirection();
    final int absoluteGravity = Gravity.getAbsoluteGravity(gravity, layoutDirection);
    final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;

    int childLeft;
    int childTop;
    switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
      case Gravity.CENTER_HORIZONTAL:
        childLeft =
            (getWidth() + getPaddingLeft() - getPaddingRight() - w) / 2
                + lp.leftMargin
                - lp.rightMargin;
        break;
      case Gravity.END:
        childLeft = getWidth() + getPaddingRight() - w - lp.rightMargin;
        break;
      case Gravity.START:
      default:
        childLeft = getPaddingLeft() + lp.leftMargin;
        break;
    }
    switch (verticalGravity) {
      case Gravity.CENTER_VERTICAL:
        childTop =
            (getHeight() + getPaddingTop() - getPaddingBottom() - h) / 2
                + lp.topMargin
                - lp.bottomMargin;
        break;
      case Gravity.BOTTOM:
        childTop = getHeight() - getPaddingBottom() - h - lp.bottomMargin;
        break;
      case Gravity.TOP:
      default:
        childTop = getPaddingTop() + lp.topMargin;
        break;
    }

    child.layout(childLeft, childTop, childLeft + w, childTop + h);
  }