コード例 #1
0
  @SuppressWarnings("MagicConstant")
  private IcsLinearLayout findOrInitializeLayout(final View convertView) {
    IcsLinearLayout layout;

    if (convertView == null || !(convertView instanceof IcsLinearLayout)) {
      layout = new IcsLinearLayout(context, null);
      if (listView.isDebugging()) layout.setBackgroundColor(Color.parseColor("#83F27B"));

      layout.setShowDividers(IcsLinearLayout.SHOW_DIVIDER_MIDDLE);
      layout.setDividerDrawable(
          context.getResources().getDrawable(R.drawable.item_divider_horizontal));

      layout.setLayoutParams(
          new AbsListView.LayoutParams(
              AbsListView.LayoutParams.MATCH_PARENT, AbsListView.LayoutParams.WRAP_CONTENT));
    } else layout = (IcsLinearLayout) convertView;

    // Clear all layout children before starting
    for (int j = 0; j < layout.getChildCount(); j++) {
      IcsLinearLayout tempChild = (IcsLinearLayout) layout.getChildAt(j);
      linearLayoutPool.put(tempChild);
      for (int k = 0; k < tempChild.getChildCount(); k++) viewPool.put(tempChild.getChildAt(k));
      tempChild.removeAllViews();
    }
    layout.removeAllViews();

    return layout;
  }
コード例 #2
0
  @Override
  public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    final boolean lockedExpanded = widthMode == MeasureSpec.EXACTLY;
    setFillViewport(lockedExpanded);

    final int childCount = mTabLayout.getChildCount();
    if (childCount > 1 && (widthMode == MeasureSpec.EXACTLY || widthMode == MeasureSpec.AT_MOST)) {
      if (childCount > 2) {
        mMaxTabWidth = (int) (MeasureSpec.getSize(widthMeasureSpec) * 0.4f);
      } else {
        mMaxTabWidth = MeasureSpec.getSize(widthMeasureSpec) / 2;
      }
    } else {
      mMaxTabWidth = -1;
    }

    final int oldWidth = getMeasuredWidth();
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    final int newWidth = getMeasuredWidth();

    if (lockedExpanded && oldWidth != newWidth) {
      // Recenter the tab display if we're at a new (scrollable) size.
      setCurrentItem(mSelectedTabIndex);
    }
  }
コード例 #3
0
 public void setTabSelected(int position) {
   mSelectedTabIndex = position;
   final int tabCount = mTabLayout.getChildCount();
   for (int i = 0; i < tabCount; i++) {
     final View child = mTabLayout.getChildAt(i);
     final boolean isSelected = i == position;
     child.setSelected(isSelected);
     if (isSelected) {
       animateToTab(position);
     }
   }
 }
コード例 #4
0
  @Override
  public void setCurrentItem(int item) {
    if (mViewPager == null) {
      throw new IllegalStateException("ViewPager has not been bound.");
    }
    mSelectedTabIndex = item;
    mViewPager.setCurrentItem(item);

    final int tabCount = mTabLayout.getChildCount();
    for (int i = 0; i < tabCount; i++) {
      final View child = mTabLayout.getChildAt(i);
      final boolean isSelected = (i == item);
      child.setSelected(isSelected);
      if (isSelected) {
        animateToTab(item);
      }
    }
  }
コード例 #5
0
  @Override
  public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    final boolean lockedExpanded = widthMode == MeasureSpec.EXACTLY;
    setFillViewport(lockedExpanded);

    final int childCount = mTabLayout.getChildCount();
    if (childCount > 1 && (widthMode == MeasureSpec.EXACTLY || widthMode == MeasureSpec.AT_MOST)) {
      if (childCount > 2) {
        mMaxTabWidth = (int) (MeasureSpec.getSize(widthMeasureSpec) * 0.4f);
      } else {
        mMaxTabWidth = MeasureSpec.getSize(widthMeasureSpec) / 2;
      }
    } else {
      mMaxTabWidth = -1;
    }

    heightMeasureSpec = MeasureSpec.makeMeasureSpec(mContentHeight, MeasureSpec.EXACTLY);

    final boolean canCollapse = !lockedExpanded && mAllowCollapse;

    if (canCollapse) {
      // See if we should expand
      mTabLayout.measure(MeasureSpec.UNSPECIFIED, heightMeasureSpec);
      if (mTabLayout.getMeasuredWidth() > MeasureSpec.getSize(widthMeasureSpec)) {
        performCollapse();
      } else {
        performExpand();
      }
    } else {
      performExpand();
    }

    final int oldWidth = getMeasuredWidth();
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    final int newWidth = getMeasuredWidth();

    if (lockedExpanded && oldWidth != newWidth) {
      // Recenter the tab display if we're at a new (scrollable) size.
      setTabSelected(mSelectedTabIndex);
    }
  }