/**
   * 如果有新的数据到达,则需要填充新数据 该接口未测试,有需要的同学请自行脑补
   *
   * @param appendList 新数据列表
   */
  public void appendData(List<CardDataItem> appendList) {
    dataList.addAll(appendList);

    int currentIndex = isShowing;
    int num = viewList.size();
    for (int i = 0; i < num; i++) {
      CardItemView itemView = viewList.get(i);
      itemView.setVisibility(View.VISIBLE);
      itemView.fillData(dataList.get(currentIndex++));
    }
  }
  /**
   * 本来想写成Adapter适配,想想还是算了,这种比较简单
   *
   * @param dataList 数据
   */
  public void fillData(List<CardDataItem> dataList) {
    this.dataList = dataList;

    int num = viewList.size();
    for (int i = 0; i < num; i++) {
      CardItemView itemView = (CardItemView) viewList.get(i);
      itemView.fillData(dataList.get(i));
      itemView.setVisibility(View.VISIBLE);
    }

    if (null != cardSwitchListener) {
      cardSwitchListener.onShow(0);
    }
  }
  /** 对View重新排序 */
  private void orderViewStack() {
    synchronized (obj1) {
      if (releasedViewList.size() == 0) {
        return;
      }

      CardItemView changedView = (CardItemView) releasedViewList.get(0);
      if (changedView.getLeft() == initCenterViewX) {
        return;
      }

      // 1. 消失的卡片View位置重置
      changedView.offsetLeftAndRight(initCenterViewX - changedView.getLeft());
      changedView.offsetTopAndBottom(initCenterViewY - changedView.getTop() + yOffsetStep * 2);
      float scale = 1.0f - SCALE_STEP * 2;
      changedView.setScaleX(scale);
      changedView.setScaleY(scale);

      // 2. 卡片View在ViewGroup中的顺次调整
      int num = viewList.size();
      for (int i = num - 1; i > 0; i--) {
        View tempView = viewList.get(i);
        tempView.bringToFront();
      }

      // 3. changedView填充新数据
      int newIndex = isShowing + 4;
      if (newIndex < dataList.size()) {
        CardDataItem dataItem = dataList.get(newIndex);
        changedView.fillData(dataItem);
      } else {
        changedView.setVisibility(View.INVISIBLE);
      }

      // 4. viewList中的卡片view的位次调整
      viewList.remove(changedView);
      viewList.add(changedView);
      releasedViewList.remove(0);

      // 5. 更新showIndex、接口回调
      if (isShowing + 1 < dataList.size()) {
        isShowing++;
      }
      if (null != cardSwitchListener) {
        cardSwitchListener.onShow(isShowing);
      }
    }
  }
  @Override
  protected void onFinishInflate() {
    super.onFinishInflate();

    // 渲染完成,初始化卡片view列表
    viewList.clear();
    int num = getChildCount();
    for (int i = num - 1; i >= 0; i--) {
      View childView = getChildAt(i);
      if (childView.getId() == R.id.card_bottom_layout) {
        bottomLayout = childView;
        initBottomLayout();
      } else {
        CardItemView viewItem = (CardItemView) childView;
        viewItem.setTag(i + 1);
        viewList.add(viewItem);
      }
    }
  }