Exemplo n.º 1
0
  /**
   * Calculates control width and creates text layouts
   *
   * @param widthSize the input layout width
   * @param mode the layout mode
   * @return the calculated control width
   */
  private int calculateLayoutWidth(int widthSize, int mode) {
    initResourcesIfNecessary();

    // TODO: make it static
    itemsLayout.setLayoutParams(
        new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    itemsLayout.measure(
        MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.UNSPECIFIED),
        MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    int width = itemsLayout.getMeasuredWidth();

    if (mode == MeasureSpec.EXACTLY) {
      width = widthSize;
    } else {
      width += 2 * PADDING;

      // Check against our minimum width
      width = Math.max(width, getSuggestedMinimumWidth());

      if (mode == MeasureSpec.AT_MOST && widthSize < width) {
        width = widthSize;
      }
    }

    itemsLayout.measure(
        MeasureSpec.makeMeasureSpec(width - 2 * PADDING, MeasureSpec.EXACTLY),
        MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));

    return width;
  }
  private void init(Context context) {
    // 设置滑动效果
    animation =
        new RotateAnimation(
            0,
            -180,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f);
    animation.setInterpolator(new LinearInterpolator());
    animation.setDuration(100);
    animation.setFillAfter(true);

    reverseAnimation =
        new RotateAnimation(
            -180,
            0,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f);
    reverseAnimation.setInterpolator(new LinearInterpolator());
    reverseAnimation.setDuration(100);
    reverseAnimation.setFillAfter(true);

    inflater = LayoutInflater.from(context);
    headView = (LinearLayout) inflater.inflate(R.layout.pull_to_refresh_head, null);

    arrowImageView = (ImageView) headView.findViewById(R.id.head_arrowImageView);
    arrowImageView.setMinimumWidth(50);
    arrowImageView.setMinimumHeight(50);
    progressBar = (ProgressBar) headView.findViewById(R.id.head_progressBar);
    tipsTextview = (TextView) headView.findViewById(R.id.head_tipsTextView);
    lastUpdatedTextView = (TextView) headView.findViewById(R.id.head_lastUpdatedTextView);

    headContentOriginalTopPadding = headView.getPaddingTop();

    measureView(headView);
    headContentHeight = headView.getMeasuredHeight();
    headContentWidth = headView.getMeasuredWidth();

    headView.setPadding(
        headView.getPaddingLeft(),
        -1 * headContentHeight,
        headView.getPaddingRight(),
        headView.getPaddingBottom());
    headView.invalidate();

    // System.out.println("初始高度�?+headContentHeight);
    // System.out.println("初始TopPad�?+headContentOriginalTopPadding);

    addHeaderView(headView);
    setOnScrollListener(this);
  }
  private void init(Context context) {
    setCacheColorHint(context.getResources().getColor(R.color.transparent));
    inflater = LayoutInflater.from(context);

    headView = (LinearLayout) inflater.inflate(R.layout.head, null); // listview拼接headview

    arrowImageView = (ImageView) headView.findViewById(R.id.head_arrowImageView);
    arrowImageView.setMinimumWidth(70);
    arrowImageView.setMinimumHeight(50);
    progressBar = (ProgressBar) headView.findViewById(R.id.head_progressBar);
    tipsTextview = (TextView) headView.findViewById(R.id.head_tipsTextView);
    lastUpdatedTextView = (TextView) headView.findViewById(R.id.head_lastUpdatedTextView);

    measureView(headView);
    headContentHeight = headView.getMeasuredHeight(); // 头部高度
    headContentWidth = headView.getMeasuredWidth(); // 头部宽度

    headView.setPadding(
        0, -1 * headContentHeight, 0, 0); // setPadding(int left, int top, int right, int bottom)
    headView.invalidate(); // Invalidate the whole view

    Log.v("size", "width:" + headContentWidth + " height:" + headContentHeight);

    addHeaderView(headView, null, false); // 添加进headview
    setOnScrollListener(this); // 滚动监听

    animation =
        new RotateAnimation(
            0,
            -180,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f);
    animation.setInterpolator(new LinearInterpolator());
    animation.setDuration(250);
    animation.setFillAfter(true); // 特效animation设置

    reverseAnimation =
        new RotateAnimation(
            -180,
            0,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f);
    reverseAnimation.setInterpolator(new LinearInterpolator());
    reverseAnimation.setDuration(200);
    reverseAnimation.setFillAfter(true); // 特效reverseAnimation设置

    state = DONE;
    isRefreshable = false;
  }
Exemplo n.º 4
0
  private void init(Context context) {
    // TODO Auto-generated method stub
    inflater = LayoutInflater.from(context);

    headView = (LinearLayout) inflater.inflate(R.layout.list_head, null);

    arrowImageView = (ImageView) headView.findViewById(R.id.head_arrowImageView);
    arrowImageView.setMinimumWidth(70);
    arrowImageView.setMinimumHeight(50);
    progressBar = (ProgressBar) headView.findViewById(R.id.head_progressBar);
    tipsTextview = (TextView) headView.findViewById(R.id.head_tipsTextView);
    lastUpdatedTextView = (TextView) headView.findViewById(R.id.head_lastUpdatedTextView);

    headView.setLayoutParams(
        new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    // measureView(this);
    measureView(headView);
    headContentHeight = headView.getMeasuredHeight();
    headContentWidth = headView.getMeasuredWidth();

    this.setPadding(0, -1 * headContentHeight, 0, 0);
    this.invalidate();

    animation =
        new RotateAnimation(
            0,
            -180,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f);
    animation.setInterpolator(new LinearInterpolator());
    animation.setDuration(250);
    animation.setFillAfter(true);

    reverseAnimation =
        new RotateAnimation(
            -180,
            0,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f);
    reverseAnimation.setInterpolator(new LinearInterpolator());
    reverseAnimation.setDuration(200);
    reverseAnimation.setFillAfter(true);

    state = DONE;

    isRefreshable = false;
  }
Exemplo n.º 5
0
  private void init(Context context) {
    LayoutInflater inflater = LayoutInflater.from(context);
    innerLayout = new LinearLayout(context);
    innerLayout.setLayoutParams(
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
    innerLayout.setOrientation(LinearLayout.VERTICAL);

    headView = (LinearLayout) inflater.inflate(R.layout.pull_homeactivity_refreshscrollview, null);

    arrowImageView = (ImageView) headView.findViewById(R.id.head_arrowImageView);
    progressBar = (ProgressBar) headView.findViewById(R.id.head_progressBar);
    tipsTextview = (TextView) headView.findViewById(R.id.head_tipsTextView);
    lastUpdatedTextView = (TextView) headView.findViewById(R.id.head_lastUpdatedTextView);
    measureView(headView);

    headContentHeight = headView.getMeasuredHeight();
    headContentWidth = headView.getMeasuredWidth();
    headView.setPadding(0, -1 * headContentHeight, 0, 0);
    headView.invalidate();

    innerLayout.addView(headView);
    addView(innerLayout);

    animation =
        new RotateAnimation(
            0,
            -180,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f);
    animation.setInterpolator(new LinearInterpolator());
    animation.setDuration(250);
    animation.setFillAfter(true);

    reverseAnimation =
        new RotateAnimation(
            -180,
            0,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f);
    reverseAnimation.setInterpolator(new LinearInterpolator());
    reverseAnimation.setDuration(200);
    reverseAnimation.setFillAfter(true);

    state = DONE;
    isRefreshable = false;
    canReturn = false;
  }
Exemplo n.º 6
0
  /**
   * 添加下拉刷新的HeadView
   *
   * @date 2013-11-11 下午9:48:26
   * @change JohnWatson
   * @version 1.0
   */
  private void addHeadView() {
    mHeadView = (LinearLayout) mInflater.inflate(com.gemptc.activities.R.layout.head, null);

    LinearLayout head_linetest =
        (LinearLayout) mHeadView.findViewById(com.gemptc.activities.R.id.head_linetest);

    mArrowImageView = (ImageView) mHeadView.findViewById(R.id.head_arrowImageView);
    mArrowImageView.setMinimumWidth(70);
    mArrowImageView.setMinimumHeight(50);
    mProgressBar = (ProgressBar) mHeadView.findViewById(R.id.head_progressBar);
    mTipsTextView = (TextView) mHeadView.findViewById(R.id.head_tipsTextView);
    mLastUpdatedTextView = (TextView) mHeadView.findViewById(R.id.head_lastUpdatedTextView);

    measureView(mHeadView);
    mHeadViewHeight = mHeadView.getMeasuredHeight();
    mHeadViewWidth = mHeadView.getMeasuredWidth();

    int x = mHeadView.getMeasuredWidth();
    int x1 = mHeadView.getWidth();
    int y1 = mHeadView.getHeight();
    int y = mHeadView.getMeasuredHeight();

    int x12 = head_linetest.getMeasuredWidth();
    int x11 = head_linetest.getWidth();
    int y11 = head_linetest.getHeight();
    int y12 = head_linetest.getMeasuredHeight();

    mHeadView.setPadding(0, -1 * mHeadViewHeight, 0, 0);
    mHeadView.invalidate();

    Log.v("size", "width:" + mHeadViewWidth + " height:" + mHeadViewHeight);

    addHeaderView(mHeadView, null, false);

    mHeadState = DONE;
  }
 @Override
 public void setBackgroundLayoutSize(LinearLayout layoutBackground) {
   if (layoutBackground != null) {
     int height, width;
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
       width = layoutBackground.getMeasuredWidth();
       height = layoutBackground.getMeasuredHeight();
     } else {
       width = layoutBackground.getWidth();
       height = layoutBackground.getHeight();
     }
     if (height - (getPadding() * 2) == 0) {
       height = (int) dp2px(DEFAULT_PROGRESS_BAR_HEIGHT);
     }
     setBackgroundWidth(width);
     setBackgroundHeight(height);
   }
 }
Exemplo n.º 8
0
  @Click(R.id.actionbar_more)
  void moreClicked() {
    mActionbarMore.setSelected(true);
    LinearLayout moreContentView =
        (LinearLayout) mInflater.inflate(R.layout.main_more_content, null);

    moreContentView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
    final PopupWindow popupWindow = new PopupWindow(this);
    popupWindow.setBackgroundDrawable(
        new ColorDrawable(getResources().getColor(R.color.red_dark_washedout)));
    popupWindow.setContentView(moreContentView);
    popupWindow.showAsDropDown(mActionbarMore);
    popupWindow.setTouchable(true);
    popupWindow.setFocusable(true);
    popupWindow.setOutsideTouchable(true);
    popupWindow.setOnDismissListener(
        new OnDismissListener() {
          public void onDismiss() {
            mActionbarMore.setSelected(false);
          }
        });

    Button settingsButton = (Button) moreContentView.findViewById(R.id.main_more_content_settings);
    settingsButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            startActivity(new Intent(MainActivity.this, SettingsActivity.class));
            popupWindow.dismiss();
          }
        });

    Button aboutButton = (Button) moreContentView.findViewById(R.id.main_more_content_about);
    aboutButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            startActivity(new Intent(MainActivity.this, AboutActivity_.class));
            popupWindow.dismiss();
          }
        });

    popupWindow.update(moreContentView.getMeasuredWidth(), moreContentView.getMeasuredHeight());
  }
  /**
   * 添加下拉刷新的HeadView
   *
   * @date 2013-11-11 下午9:48:26
   * @change JohnWatson
   * @version 1.0
   */
  private void addHeadView() {
    mHeadRootView = (LinearLayout) mInflater.inflate(R.layout.pull_to_refresh_head, null);

    mArrowImageView = (ImageView) mHeadRootView.findViewById(R.id.head_arrowImageView);
    mArrowImageView.setMinimumWidth(70);
    mArrowImageView.setMinimumHeight(50);
    mProgressBar = (ImageView) mHeadRootView.findViewById(R.id.head_progressBar);
    mTipsTextView = (TextView) mHeadRootView.findViewById(R.id.head_tipsTextView);
    mLastUpdatedTextView = (TextView) mHeadRootView.findViewById(R.id.head_lastUpdatedTextView);

    measureView(mHeadRootView);
    mHeadViewHeight = mHeadRootView.getMeasuredHeight();
    mHeadViewWidth = mHeadRootView.getMeasuredWidth();

    mHeadRootView.setPadding(0, -1 * mHeadViewHeight, 0, 0);
    mHeadRootView.invalidate();

    Log.v("size", "width:" + mHeadViewWidth + " height:" + mHeadViewHeight);

    addHeaderView(mHeadRootView, null, false);

    mHeadState = DONE;
    changeHeadViewByState();
  }
 /**
  * Returns how big this panel's view should be. This method should only be called when the view
  * has not been attached to a parent.
  *
  * @throws IllegalStateException
  */
 public Size measure() {
   Preconditions.checkState(mContentView.getParent() == null);
   mContentView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
   return new Size(mContentView.getMeasuredWidth(), mContentView.getMeasuredHeight());
 }
Exemplo n.º 11
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final int childCount = getChildCount();
    if (mIsCollapsable) {
      int visibleChildren = 0;
      for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE
            && !(child == mMenuView && mMenuView.getChildCount() == 0)) {
          visibleChildren++;
        }
      }

      if (visibleChildren == 0) {
        // No size for an empty action bar when collapsable.
        setMeasuredDimension(0, 0);
        mIsCollapsed = true;
        return;
      }
    }
    mIsCollapsed = false;

    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    if (widthMode != MeasureSpec.EXACTLY) {
      throw new IllegalStateException(
          getClass().getSimpleName()
              + " can only be used "
              + "with android:layout_width=\"match_parent\" (or fill_parent)");
    }

    int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    if (heightMode != MeasureSpec.AT_MOST) {
      throw new IllegalStateException(
          getClass().getSimpleName()
              + " can only be used "
              + "with android:layout_height=\"wrap_content\"");
    }

    int contentWidth = MeasureSpec.getSize(widthMeasureSpec);

    int maxHeight = mContentHeight > 0 ? mContentHeight : MeasureSpec.getSize(heightMeasureSpec);

    final int verticalPadding = getPaddingTop() + getPaddingBottom();
    final int paddingLeft = getPaddingLeft();
    final int paddingRight = getPaddingRight();
    final int height = maxHeight - verticalPadding;
    final int childSpecHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST);

    int availableWidth = contentWidth - paddingLeft - paddingRight;
    int leftOfCenter = availableWidth / 2;
    int rightOfCenter = leftOfCenter;

    HomeView homeLayout = mExpandedActionView != null ? mExpandedHomeLayout : mHomeLayout;

    if (homeLayout.getVisibility() != GONE) {
      final ViewGroup.LayoutParams lp = homeLayout.getLayoutParams();
      int homeWidthSpec;
      if (lp.width < 0) {
        homeWidthSpec = MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST);
      } else {
        homeWidthSpec = MeasureSpec.makeMeasureSpec(lp.width, MeasureSpec.EXACTLY);
      }
      homeLayout.measure(homeWidthSpec, MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
      final int homeWidth = homeLayout.getMeasuredWidth() + homeLayout.getLeftOffset();
      availableWidth = Math.max(0, availableWidth - homeWidth);
      leftOfCenter = Math.max(0, availableWidth - homeWidth);
    }

    if (mMenuView != null && mMenuView.getParent() == this) {
      availableWidth = measureChildView(mMenuView, availableWidth, childSpecHeight, 0);
      rightOfCenter = Math.max(0, rightOfCenter - mMenuView.getMeasuredWidth());
    }

    if (mIndeterminateProgressView != null && mIndeterminateProgressView.getVisibility() != GONE) {
      availableWidth =
          measureChildView(mIndeterminateProgressView, availableWidth, childSpecHeight, 0);
      rightOfCenter = Math.max(0, rightOfCenter - mIndeterminateProgressView.getMeasuredWidth());
    }

    final boolean showTitle =
        mTitleLayout != null
            && mTitleLayout.getVisibility() != GONE
            && (mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0;

    if (mExpandedActionView == null) {
      switch (mNavigationMode) {
        case ActionBar.NAVIGATION_MODE_LIST:
          if (mListNavLayout != null) {
            final int itemPaddingSize = showTitle ? mItemPadding * 2 : mItemPadding;
            availableWidth = Math.max(0, availableWidth - itemPaddingSize);
            leftOfCenter = Math.max(0, leftOfCenter - itemPaddingSize);
            mListNavLayout.measure(
                MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST),
                MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
            final int listNavWidth = mListNavLayout.getMeasuredWidth();
            availableWidth = Math.max(0, availableWidth - listNavWidth);
            leftOfCenter = Math.max(0, leftOfCenter - listNavWidth);
          }
          break;
        case ActionBar.NAVIGATION_MODE_TABS:
          if (mTabScrollView != null) {
            final int itemPaddingSize = showTitle ? mItemPadding * 2 : mItemPadding;
            availableWidth = Math.max(0, availableWidth - itemPaddingSize);
            leftOfCenter = Math.max(0, leftOfCenter - itemPaddingSize);
            mTabScrollView.measure(
                MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST),
                MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
            final int tabWidth = mTabScrollView.getMeasuredWidth();
            availableWidth = Math.max(0, availableWidth - tabWidth);
            leftOfCenter = Math.max(0, leftOfCenter - tabWidth);
          }
          break;
      }
    }

    View customView = null;
    if (mExpandedActionView != null) {
      customView = mExpandedActionView;
    } else if ((mDisplayOptions & ActionBar.DISPLAY_SHOW_CUSTOM) != 0 && mCustomNavView != null) {
      customView = mCustomNavView;
    }

    if (customView != null) {
      final ViewGroup.LayoutParams lp = generateLayoutParams(customView.getLayoutParams());
      final ActionBar.LayoutParams ablp =
          lp instanceof ActionBar.LayoutParams ? (ActionBar.LayoutParams) lp : null;

      int horizontalMargin = 0;
      int verticalMargin = 0;
      if (ablp != null) {
        horizontalMargin = ablp.leftMargin + ablp.rightMargin;
        verticalMargin = ablp.topMargin + ablp.bottomMargin;
      }

      // If the action bar is wrapping to its content height, don't allow a custom
      // view to MATCH_PARENT.
      int customNavHeightMode;
      if (mContentHeight <= 0) {
        customNavHeightMode = MeasureSpec.AT_MOST;
      } else {
        customNavHeightMode =
            lp.height != LayoutParams.WRAP_CONTENT ? MeasureSpec.EXACTLY : MeasureSpec.AT_MOST;
      }
      final int customNavHeight =
          Math.max(0, (lp.height >= 0 ? Math.min(lp.height, height) : height) - verticalMargin);

      final int customNavWidthMode =
          lp.width != LayoutParams.WRAP_CONTENT ? MeasureSpec.EXACTLY : MeasureSpec.AT_MOST;
      int customNavWidth =
          Math.max(
              0,
              (lp.width >= 0 ? Math.min(lp.width, availableWidth) : availableWidth)
                  - horizontalMargin);
      final int hgrav =
          (ablp != null ? ablp.gravity : DEFAULT_CUSTOM_GRAVITY) & Gravity.HORIZONTAL_GRAVITY_MASK;

      // Centering a custom view is treated specially; we try to center within the whole
      // action bar rather than in the available space.
      if (hgrav == Gravity.CENTER_HORIZONTAL && lp.width == LayoutParams.MATCH_PARENT) {
        customNavWidth = Math.min(leftOfCenter, rightOfCenter) * 2;
      }

      customView.measure(
          MeasureSpec.makeMeasureSpec(customNavWidth, customNavWidthMode),
          MeasureSpec.makeMeasureSpec(customNavHeight, customNavHeightMode));
      availableWidth -= horizontalMargin + customView.getMeasuredWidth();
    }

    if (mExpandedActionView == null && showTitle) {
      availableWidth =
          measureChildView(
              mTitleLayout,
              availableWidth,
              MeasureSpec.makeMeasureSpec(mContentHeight, MeasureSpec.EXACTLY),
              0);
      leftOfCenter = Math.max(0, leftOfCenter - mTitleLayout.getMeasuredWidth());
    }

    if (mContentHeight <= 0) {
      int measuredHeight = 0;
      for (int i = 0; i < childCount; i++) {
        View v = getChildAt(i);
        int paddedViewHeight = v.getMeasuredHeight() + verticalPadding;
        if (paddedViewHeight > measuredHeight) {
          measuredHeight = paddedViewHeight;
        }
      }
      setMeasuredDimension(contentWidth, measuredHeight);
    } else {
      setMeasuredDimension(contentWidth, maxHeight);
    }

    if (mContextView != null) {
      mContextView.setContentHeight(getMeasuredHeight());
    }

    if (mProgressView != null && mProgressView.getVisibility() != GONE) {
      mProgressView.measure(
          MeasureSpec.makeMeasureSpec(contentWidth - mProgressBarPadding * 2, MeasureSpec.EXACTLY),
          MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.AT_MOST));
    }
  }
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    if (widthMode != MeasureSpec.EXACTLY) {
      throw new IllegalStateException(
          getClass().getSimpleName()
              + " can only be used "
              + "with android:layout_width=\"match_parent\" (or fill_parent)");
    }

    final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    if (heightMode == MeasureSpec.UNSPECIFIED) {
      throw new IllegalStateException(
          getClass().getSimpleName()
              + " can only be used "
              + "with android:layout_height=\"wrap_content\"");
    }

    final int contentWidth = MeasureSpec.getSize(widthMeasureSpec);

    int maxHeight = mContentHeight > 0 ? mContentHeight : MeasureSpec.getSize(heightMeasureSpec);

    final int verticalPadding = getPaddingTop() + getPaddingBottom();
    int availableWidth = contentWidth - getPaddingLeft() - getPaddingRight();
    final int height = maxHeight - verticalPadding;
    final int childSpecHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST);

    if (mClose != null) {
      availableWidth = measureChildView(mClose, availableWidth, childSpecHeight, 0);
      MarginLayoutParams lp = (MarginLayoutParams) mClose.getLayoutParams();
      availableWidth -= lp.leftMargin + lp.rightMargin;
    }

    if (mMenuView != null && mMenuView.getParent() == this) {
      availableWidth = measureChildView(mMenuView, availableWidth, childSpecHeight, 0);
    }

    if (mTitleLayout != null && mCustomView == null) {
      if (mTitleOptional) {
        final int titleWidthSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
        mTitleLayout.measure(titleWidthSpec, childSpecHeight);
        final int titleWidth = mTitleLayout.getMeasuredWidth();
        final boolean titleFits = titleWidth <= availableWidth;
        if (titleFits) {
          availableWidth -= titleWidth;
        }
        mTitleLayout.setVisibility(titleFits ? VISIBLE : GONE);
      } else {
        availableWidth = measureChildView(mTitleLayout, availableWidth, childSpecHeight, 0);
      }
    }

    if (mCustomView != null) {
      ViewGroup.LayoutParams lp = mCustomView.getLayoutParams();
      final int customWidthMode =
          lp.width != LayoutParams.WRAP_CONTENT ? MeasureSpec.EXACTLY : MeasureSpec.AT_MOST;
      final int customWidth = lp.width >= 0 ? Math.min(lp.width, availableWidth) : availableWidth;
      final int customHeightMode =
          lp.height != LayoutParams.WRAP_CONTENT ? MeasureSpec.EXACTLY : MeasureSpec.AT_MOST;
      final int customHeight = lp.height >= 0 ? Math.min(lp.height, height) : height;
      mCustomView.measure(
          MeasureSpec.makeMeasureSpec(customWidth, customWidthMode),
          MeasureSpec.makeMeasureSpec(customHeight, customHeightMode));
    }

    if (mContentHeight <= 0) {
      int measuredHeight = 0;
      final int count = getChildCount();
      for (int i = 0; i < count; i++) {
        View v = getChildAt(i);
        int paddedViewHeight = v.getMeasuredHeight() + verticalPadding;
        if (paddedViewHeight > measuredHeight) {
          measuredHeight = paddedViewHeight;
        }
      }
      setMeasuredDimension(contentWidth, measuredHeight);
    } else {
      setMeasuredDimension(contentWidth, maxHeight);
    }
  }
Exemplo n.º 13
0
  private void init(Context context) {
    inflater = LayoutInflater.from(context);
    headView =
        (LinearLayout) inflater.inflate(R.layout.list_refresh_head, null); // listview拼接headview
    footView = inflater.inflate(R.layout.list_more_view, null);
    footView.setVisibility(View.GONE);

    footView.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            if (onLoadaMoreListener != null) {
              onLoadaMoreListener.onLoadMore();
            }
          }
        });

    arrowImageView = (ImageView) headView.findViewById(R.id.array); // headview中各view
    arrowImageView.setMinimumWidth(50);
    arrowImageView.setMinimumHeight(50);
    progressBar = (ProgressBar) headView.findViewById(R.id.progressBar); // headview中各view
    tipsTextview = (TextView) headView.findViewById(R.id.tips); // headview中各view
    lastUpdatedTextView = (TextView) headView.findViewById(R.id.content); // headview中各view

    measureView(headView);
    headContentHeight = headView.getMeasuredHeight(); // 头部高度
    headContentWidth = headView.getMeasuredWidth(); // 头部宽度

    headView.setPadding(
        0, -1 * headContentHeight, 0, 0); // setPadding(int left, int top, int right, int bottom)
    headView.invalidate(); // Invalidate the whole view

    addHeaderView(headView); // 添加进headview
    addFooterView(footView);

    setOnScrollListener(this); // 滚动监听

    animation =
        new RotateAnimation(
            0,
            -180,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f);
    animation.setInterpolator(new LinearInterpolator());
    animation.setDuration(250);
    animation.setFillAfter(true); // 特效animation设置

    reverseAnimation =
        new RotateAnimation(
            -180,
            0,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f);
    reverseAnimation.setInterpolator(new LinearInterpolator());
    reverseAnimation.setDuration(250);
    reverseAnimation.setFillAfter(true); // 特效reverseAnimation设置
  }