@Override
  protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    super.onLayout(changed, left, top, right, bottom);
    try {
      // if we don't have an adapter, we don't need to do anything
      if (mAdapter == null) {
        return;
      }

      mInLayout = true;
      final int adapterCount = mAdapter.getCount();
      System.out.println(adapterCount + " /// ");
      if (adapterCount == 0) {
        removeAllViewsInLayout();
      } else {
        View topCard = getChildAt(LAST_OBJECT_IN_STACK);
        if (mActiveCard != null && topCard != null && topCard == mActiveCard) {
          removeViewsInLayout(0, LAST_OBJECT_IN_STACK);
          layoutChildren(1, adapterCount);
        } else {
          // Reset the UI and set top view listener
          removeAllViewsInLayout();
          layoutChildren(0, adapterCount);
          setTopView();
        }
      }

      mInLayout = false;

      if (adapterCount < MAX_VISIBLE) mFlingListener.onAdapterAboutToEmpty(adapterCount);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  @Override
  protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    super.onLayout(changed, left, top, right, bottom);
    // if we don't have an adapter, we don't need to do anything
    if (mAdapter == null) {
      return;
    }

    mInLayout = true;
    final int adapterCount = mAdapter.getCount();

    if (adapterCount == 0) {
      removeAllViewsInLayout();
    } else {
      View topCard = getChildAt(LAST_OBJECT_IN_STACK);
      if (mActiveCard != null && topCard != null && topCard == mActiveCard) {
        if (this.flingCardListener.isTouching()) {
          PointF lastPoint = this.flingCardListener.getLastPoint();
          if (this.mLastTouchPoint == null || !this.mLastTouchPoint.equals(lastPoint)) {
            this.mLastTouchPoint = lastPoint;
            removeViewsInLayout(0, LAST_OBJECT_IN_STACK);
            layoutChildren(1, adapterCount);
          }
        }
      } else {
        // Reset the UI and set top view listener
        removeAllViewsInLayout();
        layoutChildren(0, adapterCount);
        setTopView();
      }
    }

    mInLayout = false;

    if (adapterCount <= MIN_ADAPTER_STACK) mFlingListener.onAdapterAboutToEmpty(adapterCount);
  }
 @Override
 public void requestLayout() {
   if (!mInLayout) {
     super.requestLayout();
   }
 }