예제 #1
2
  public void configureHeaderView(int groupPosition, int childPosition) {
    if (mHeaderView == null
        || mAdapter == null
        || ((ExpandableListAdapter) mAdapter).getGroupCount() == 0) {
      return;
    }

    int state = mAdapter.getTreeHeaderState(groupPosition, childPosition);

    switch (state) {
      case IphoneTreeHeaderAdapter.PINNED_HEADER_GONE:
        {
          mHeaderViewVisible = false;
          break;
        }

      case IphoneTreeHeaderAdapter.PINNED_HEADER_VISIBLE:
        {
          mAdapter.configureTreeHeader(mHeaderView, groupPosition, childPosition, MAX_ALPHA);

          if (mHeaderView.getTop() != 0) {
            mHeaderView.layout(0, 0, mHeaderViewWidth, mHeaderViewHeight);
          }

          mHeaderViewVisible = true;

          break;
        }

      case IphoneTreeHeaderAdapter.PINNED_HEADER_PUSHED_UP:
        {
          View firstView = getChildAt(0);
          int bottom = firstView.getBottom();

          // intitemHeight = firstView.getHeight();
          int headerHeight = mHeaderView.getHeight();

          int y;

          int alpha;

          if (bottom < headerHeight) {
            y = (bottom - headerHeight);
            alpha = MAX_ALPHA * (headerHeight + y) / headerHeight;
          } else {
            y = 0;
            alpha = MAX_ALPHA;
          }

          mAdapter.configureTreeHeader(mHeaderView, groupPosition, childPosition, alpha);

          if (mHeaderView.getTop() != y) {
            mHeaderView.layout(0, y, mHeaderViewWidth, mHeaderViewHeight + y);
          }

          mHeaderViewVisible = true;
          break;
        }
    }
  }
예제 #2
0
  /** 点击了 Group 触发的事件 , 要根据根据当前点击 Group 的状态来 */
  @Override
  public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
    if (mAdapter.getHeadViewClickStatus(groupPosition) == 0) {
      mAdapter.onHeadViewClick(groupPosition, 1);
      parent.expandGroup(groupPosition);
      parent.setSelectedGroup(groupPosition);

    } else if (mAdapter.getHeadViewClickStatus(groupPosition) == 1) {
      mAdapter.onHeadViewClick(groupPosition, 0);
      parent.collapseGroup(groupPosition);
    }

    // 返回 true 才可以弹回第一行 , 不知道为什么
    return true;
  }
예제 #3
0
  /** 点击 HeaderView 触发的事件 */
  private void headerViewClick() {
    long packedPosition = getExpandableListPosition(this.getFirstVisiblePosition());

    int groupPosition = ExpandableListView.getPackedPositionGroup(packedPosition);

    if (mAdapter.getHeadViewClickStatus(groupPosition) == 1) {
      this.collapseGroup(groupPosition);
      mAdapter.onHeadViewClick(groupPosition, 0);
    } else {
      this.expandGroup(groupPosition);
      mAdapter.onHeadViewClick(groupPosition, 1);
    }

    this.setSelectedGroup(groupPosition);
  }
예제 #4
0
  @Override
  protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    super.onLayout(changed, left, top, right, bottom);
    final long flatPostion = getExpandableListPosition(getFirstVisiblePosition());
    final int groupPos = ExpandableListView.getPackedPositionGroup(flatPostion);
    final int childPos = ExpandableListView.getPackedPositionChild(flatPostion);
    int state = mAdapter.getTreeHeaderState(groupPos, childPos);
    if (mHeaderView != null && mAdapter != null && state != mOldState) {
      mOldState = state;
      mHeaderView.layout(0, 0, mHeaderViewWidth, mHeaderViewHeight);
    }

    configureHeaderView(groupPos, childPos);
  }