Java Code Examples for android.view.View.isLayoutRequested()

The following are Jave code examples for showing how to use isLayoutRequested() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: cwac-crossport   File: CoordinatorLayout.java   Source Code and License Vote up 6 votes
/**
   * Get the position rect for the given child. If the child has currently requested layout
   * or has a visibility of GONE.
 *
 * @param child child view to check
   * @param transform true to include transformation in the output rect, false to
   *                        only account for the base position
 * @param out rect to set to the output values
 */
void getChildRect(View child, boolean transform, Rect out) {
  if (child.isLayoutRequested() || child.getVisibility() == View.GONE) {
    out.setEmpty();
    return;
  }
  if (transform) {
    getDescendantRect(child, out);
  } else {
    out.set(child.getLeft(), child.getTop(), child.getRight(), child.getBottom());
  }
}
 
Example 2
Project: RNLearn_Project1   File: FlatViewGroup.java   Source Code and License Vote up 6 votes
private void processLayoutRequest() {
  mIsLayoutRequested = false;
  for (int i = 0, childCount = getChildCount(); i != childCount; ++i) {
    View child = getChildAt(i);
    if (!child.isLayoutRequested()) {
      continue;
    }

    child.measure(
      MeasureSpec.makeMeasureSpec(child.getWidth(), MeasureSpec.EXACTLY),
      MeasureSpec.makeMeasureSpec(child.getHeight(), MeasureSpec.EXACTLY));
    child.layout(child.getLeft(), child.getTop(), child.getRight(), child.getBottom());
  }
}
 
Example 3
Project: PlusGram   File: SectionsListView.java   Source Code and License Vote up 6 votes
private void ensurePinnedHeaderLayout(View header, boolean forceLayout) {
    if (header.isLayoutRequested() || forceLayout) {
        int widthSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.EXACTLY);
        int heightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
        try {
            header.measure(widthSpec, heightSpec);
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
        header.layout(0, 0, header.getMeasuredWidth(), header.getMeasuredHeight());
    }
}
 
Example 4
Project: PicShow-zhaipin   File: RecyclerIndicatorView.java   Source Code and License Vote up 6 votes
private int measureScrollBar(int position, float selectPercent, boolean needChange) {
    if (scrollBar == null)
        return 0;
    View view = scrollBar.getSlideView();
    if (view.isLayoutRequested() || needChange) {
        View selectV = linearLayoutManager.findViewByPosition(position);
        View unSelectV = linearLayoutManager.findViewByPosition(position + 1);
        if (selectV != null) {
            int tabWidth = (int) (selectV.getWidth() * (1 - selectPercent) + (unSelectV == null ? 0 : unSelectV.getWidth() * selectPercent));
            int width = scrollBar.getWidth(tabWidth);
            int height = scrollBar.getHeight(getHeight());
            view.measure(width, height);
            view.layout(0, 0, width, height);
            return tabWidth;
        }
    }
    return scrollBar.getSlideView().getWidth();
}
 
Example 5
Project: PicShow-zhaipin   File: FixedIndicatorView.java   Source Code and License Vote up 6 votes
private int measureScrollBar(int position, float selectPercent, boolean needChange) {
    if (scrollBar == null)
        return 0;
    View view = scrollBar.getSlideView();
    if (view.isLayoutRequested() || needChange) {
        View selectV = getItemOutView(position);
        View unSelectV;
        if (position + 1 < mAdapter.getCount()) {
            unSelectV = getItemOutView(position + 1);
        } else {
            unSelectV = getItemOutView(0);
        }
        if (selectV != null) {
            int tabWidth = (int) (selectV.getWidth() * (1 - selectPercent) + (unSelectV == null ? 0 : unSelectV.getWidth() * selectPercent));
            int width = scrollBar.getWidth(tabWidth);
            int height = scrollBar.getHeight(getHeight());
            view.measure(width, height);
            view.layout(0, 0, width, height);
            return tabWidth;
        }
    }
    return scrollBar.getSlideView().getWidth();
}
 
Example 6
Project: ultrasonic   File: DragSortItemView.java   Source Code and License Vote up 5 votes
/**
 * 
 */
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    
    int height = MeasureSpec.getSize(heightMeasureSpec);
    int width = MeasureSpec.getSize(widthMeasureSpec);

    int heightMode = MeasureSpec.getMode(heightMeasureSpec);

    final View child = getChildAt(0);
    if (child == null) {
        setMeasuredDimension(0, width);
        return;
    }

    if (child.isLayoutRequested()) {
        // Always let child be as tall as it wants.
        measureChild(child, widthMeasureSpec,
                MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    }

    if (heightMode == MeasureSpec.UNSPECIFIED) {
        ViewGroup.LayoutParams lp = getLayoutParams();

        if (lp.height > 0) {
            height = lp.height;
        } else {
            height = child.getMeasuredHeight();
        }
    }

    setMeasuredDimension(width, height);
}
 
Example 7
Project: airgram   File: SectionsListView.java   Source Code and License Vote up 5 votes
private void ensurePinnedHeaderLayout(View header, boolean forceLayout) {
    if (header.isLayoutRequested() || forceLayout) {
        int widthSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.EXACTLY);
        int heightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
        try {
            header.measure(widthSpec, heightSpec);
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
        header.layout(0, 0, header.getMeasuredWidth(), header.getMeasuredHeight());
    }
}
 
Example 8
Project: RNLearn_Project1   File: FlatViewGroup.java   Source Code and License Vote up 5 votes
private void processLayoutRequest() {
  mIsLayoutRequested = false;
  for (int i = 0, childCount = getChildCount(); i != childCount; ++i) {
    View child = getChildAt(i);
    if (!child.isLayoutRequested()) {
      continue;
    }

    child.measure(
      MeasureSpec.makeMeasureSpec(child.getWidth(), MeasureSpec.EXACTLY),
      MeasureSpec.makeMeasureSpec(child.getHeight(), MeasureSpec.EXACTLY));
    child.layout(child.getLeft(), child.getTop(), child.getRight(), child.getBottom());
  }
}
 
Example 9
Project: NoticeDog   File: DragSortItemView.java   Source Code and License Vote up 5 votes
/**
 *
 */
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

    int height = MeasureSpec.getSize(heightMeasureSpec);
    int width = MeasureSpec.getSize(widthMeasureSpec);

    int heightMode = MeasureSpec.getMode(heightMeasureSpec);

    final View child = getChildAt(0);
    if (child == null) {
        setMeasuredDimension(0, width);
        return;
    }

    if (child.isLayoutRequested()) {
        // Always let child be as tall as it wants.
        measureChild(child, widthMeasureSpec,
                MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    }

    if (heightMode == MeasureSpec.UNSPECIFIED) {
        LayoutParams lp = getLayoutParams();

        if (lp.height > 0) {
            height = lp.height;
        } else {
            height = child.getMeasuredHeight();
        }
    }

    setMeasuredDimension(width, height);
}
 
Example 10
Project: letv   File: HListView.java   Source Code and License Vote up 5 votes
@TargetApi(11)
private void setupChild(View child, int position, int x, boolean flowDown, int childrenTop, boolean selected, boolean recycled) {
    boolean isSelected = selected && shouldShowSelector();
    boolean updateChildSelected = isSelected != child.isSelected();
    int mode = this.mTouchMode;
    boolean isPressed = mode > 0 && mode < 3 && this.mMotionPosition == position;
    boolean updateChildPressed = isPressed != child.isPressed();
    boolean needToMeasure = !recycled || updateChildSelected || child.isLayoutRequested();
    LayoutParams p = (LayoutParams) child.getLayoutParams();
    if (p == null) {
        p = (LayoutParams) generateDefaultLayoutParams();
    }
    p.viewType = this.mAdapter.getItemViewType(position);
    if ((!recycled || p.forceAdd) && !(p.recycledHeaderFooter && p.viewType == -2)) {
        p.forceAdd = false;
        if (p.viewType == -2) {
            p.recycledHeaderFooter = true;
        }
        addViewInLayout(child, flowDown ? -1 : 0, p, true);
    } else {
        attachViewToParent(child, flowDown ? -1 : 0, p);
    }
    if (updateChildSelected) {
        child.setSelected(isSelected);
    }
    if (updateChildPressed) {
        child.setPressed(isPressed);
    }
    if (!(this.mChoiceMode == 0 || this.mCheckStates == null)) {
        if (child instanceof Checkable) {
            ((Checkable) child).setChecked(((Boolean) this.mCheckStates.get(position, Boolean.valueOf(false))).booleanValue());
        } else if (VERSION.SDK_INT >= 11) {
            child.setActivated(((Boolean) this.mCheckStates.get(position, Boolean.valueOf(false))).booleanValue());
        }
    }
    if (needToMeasure) {
        int childWidthSpec;
        int childHeightSpec = ViewGroup.getChildMeasureSpec(this.mHeightMeasureSpec, this.mListPadding.top + this.mListPadding.bottom, p.height);
        int lpWidth = p.width;
        if (lpWidth > 0) {
            childWidthSpec = MeasureSpec.makeMeasureSpec(lpWidth, 1073741824);
        } else {
            childWidthSpec = MeasureSpec.makeMeasureSpec(0, 0);
        }
        child.measure(childWidthSpec, childHeightSpec);
    } else {
        cleanupLayoutState(child);
    }
    int w = child.getMeasuredWidth();
    int h = child.getMeasuredHeight();
    int childLeft = flowDown ? x : x - w;
    if (needToMeasure) {
        child.layout(childLeft, childrenTop, childLeft + w, childrenTop + h);
    } else {
        child.offsetLeftAndRight(childLeft - child.getLeft());
        child.offsetTopAndBottom(childrenTop - child.getTop());
    }
    if (this.mCachingStarted && !child.isDrawingCacheEnabled()) {
        child.setDrawingCacheEnabled(true);
    }
    if (VERSION.SDK_INT >= 11 && recycled && ((LayoutParams) child.getLayoutParams()).scrappedFromPosition != position) {
        child.jumpDrawablesToCurrentState();
    }
}
 
Example 11
Project: PlusGram   File: LetterSectionsListView.java   Source Code and License Vote up 5 votes
private void ensurePinnedHeaderLayout(View header, boolean forceLayout) {
    if (header.isLayoutRequested() || forceLayout) {
        ViewGroup.LayoutParams layoutParams = header.getLayoutParams();
        int heightSpec = MeasureSpec.makeMeasureSpec(layoutParams.height, MeasureSpec.EXACTLY);
        int widthSpec = MeasureSpec.makeMeasureSpec(layoutParams.width, MeasureSpec.EXACTLY);
        try {
            header.measure(widthSpec, heightSpec);
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
        header.layout(0, 0, header.getMeasuredWidth(), header.getMeasuredHeight());
    }
}
 
Example 12
Project: boohee_v5.6   File: PLA_ListView.java   Source Code and License Vote up 5 votes
private void setupChild(View child, int position, int y, boolean flowDown, int childrenLeft,
                        boolean selected, boolean recycled) {
    boolean isSelected = selected && shouldShowSelector();
    boolean updateChildSelected = isSelected != child.isSelected();
    int mode = this.mTouchMode;
    boolean isPressed = mode > 0 && mode < 3 && this.mMotionPosition == position;
    boolean updateChildPressed = isPressed != child.isPressed();
    boolean needToMeasure = !recycled || updateChildSelected || child.isLayoutRequested();
    ViewGroup.LayoutParams p = (LayoutParams) child.getLayoutParams();
    if (p == null) {
        ViewGroup.LayoutParams layoutParams = new LayoutParams(-1, -2, 0);
    }
    p.viewType = this.mAdapter.getItemViewType(position);
    p.scrappedFromPosition = position;
    if ((!recycled || p.forceAdd) && !(p.recycledHeaderFooter && p.viewType == -2)) {
        p.forceAdd = false;
        if (p.viewType == -2) {
            p.recycledHeaderFooter = true;
        }
        addViewInLayout(child, flowDown ? -1 : 0, p, true);
    } else {
        attachViewToParent(child, flowDown ? -1 : 0, p);
    }
    if (updateChildSelected) {
        child.setSelected(isSelected);
    }
    if (updateChildPressed) {
        child.setPressed(isPressed);
    }
    if (needToMeasure) {
        int childHeightSpec;
        int childWidthSpec = ViewGroup.getChildMeasureSpec(this.mWidthMeasureSpec, this
                .mListPadding.left + this.mListPadding.right, p.width);
        int lpHeight = p.height;
        if (lpHeight > 0) {
            childHeightSpec = MeasureSpec.makeMeasureSpec(lpHeight, 1073741824);
        } else {
            childHeightSpec = MeasureSpec.makeMeasureSpec(0, 0);
        }
        onMeasureChild(child, position, childWidthSpec, childHeightSpec);
    } else {
        cleanupLayoutState(child);
    }
    int w = child.getMeasuredWidth();
    int h = child.getMeasuredHeight();
    int childTop = flowDown ? y : y - h;
    if (needToMeasure) {
        onLayoutChild(child, position, childrenLeft, childTop, childrenLeft + w, childTop + h);
    } else {
        onOffsetChild(child, position, childrenLeft - child.getLeft(), childTop - child
                .getTop());
    }
    if (this.mCachingStarted && !child.isDrawingCacheEnabled()) {
        child.setDrawingCacheEnabled(true);
    }
}
 
Example 13
Project: boohee_v5.6   File: PinnedHeaderListView.java   Source Code and License Vote up 5 votes
private void ensurePinnedHeaderLayout(View header) {
    if (header.isLayoutRequested()) {
        int heightSpec;
        int widthSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth(), this.mWidthMode);
        LayoutParams layoutParams = header.getLayoutParams();
        if (layoutParams == null || layoutParams.height <= 0) {
            heightSpec = MeasureSpec.makeMeasureSpec(0, 0);
        } else {
            heightSpec = MeasureSpec.makeMeasureSpec(layoutParams.height, 1073741824);
        }
        header.measure(widthSpec, heightSpec);
        header.layout(0, 0, header.getMeasuredWidth(), header.getMeasuredHeight());
    }
}
 
Example 14
Project: boohee_v5.6   File: CoordinatorLayout.java   Source Code and License Vote up 5 votes
void getChildRect(View child, boolean transform, Rect out) {
    if (child.isLayoutRequested() || child.getVisibility() == 8) {
        out.set(0, 0, 0, 0);
    } else if (transform) {
        getDescendantRect(child, out);
    } else {
        out.set(child.getLeft(), child.getTop(), child.getRight(), child.getBottom());
    }
}
 
Example 15
Project: Linphone4Android   File: SlidingDrawer.java   Source Code and License Vote up 4 votes
private void prepareContent() {
	if (mAnimating) {
		return;
	}

	// Something changed in the content, we need to honor the layout request
	// before creating the cached bitmap
	final View content = mContent;
	if (content.isLayoutRequested()) {

		if (mVertical) {
			final int handleHeight = mHandleHeight;
			int height = getBottom() - getTop() - handleHeight - mTopOffset;
			content.measure(MeasureSpec.makeMeasureSpec(getRight()
					- getLeft(), MeasureSpec.EXACTLY), MeasureSpec
					.makeMeasureSpec(height, MeasureSpec.AT_MOST));

			if (mInvert)
				content.layout(0, mTopOffset, content.getMeasuredWidth(),
						mTopOffset + content.getMeasuredHeight());
			else
				content.layout(
						0,
						mTopOffset + handleHeight,
						content.getMeasuredWidth(),
						mTopOffset + handleHeight
								+ content.getMeasuredHeight());

		} else {

			final int handleWidth = mHandle.getWidth();
			int width = getRight() - getLeft() - handleWidth - mTopOffset;
			content.measure(MeasureSpec.makeMeasureSpec(width,
					MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(
					getBottom() - getTop(), MeasureSpec.EXACTLY));

			if (mInvert)
				content.layout(mTopOffset, 0,
						mTopOffset + content.getMeasuredWidth(),
						content.getMeasuredHeight());
			else
				content.layout(handleWidth + mTopOffset, 0, mTopOffset
						+ handleWidth + content.getMeasuredWidth(),
						content.getMeasuredHeight());
		}
	}
	// Try only once... we should really loop but it's not a big deal
	// if the draw was cancelled, it will only be temporary anyway
	content.getViewTreeObserver().dispatchOnPreDraw();
	content.buildDrawingCache();

	content.setVisibility(View.GONE);
}
 
Example 16
Project: SwipeCard-   File: SwipeFlingAdapterView.java   Source Code and License Vote up 4 votes
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void makeAndAddView(View child, int index) {

    FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) child.getLayoutParams();
    addViewInLayout(child, 0, lp, true);

    final boolean needToMeasure = child.isLayoutRequested();
    if (needToMeasure) {
        int childWidthSpec = getChildMeasureSpec(getWidthMeasureSpec(),
                getPaddingLeft() + getPaddingRight() + lp.leftMargin + lp.rightMargin,
                lp.width);
        int childHeightSpec = getChildMeasureSpec(getHeightMeasureSpec(),
                getPaddingTop() + getPaddingBottom() + lp.topMargin + lp.bottomMargin,
                lp.height);
        child.measure(childWidthSpec, childHeightSpec);
    } else {
        cleanupLayoutState(child);
    }

    int w = child.getMeasuredWidth();
    int h = child.getMeasuredHeight();

    int gravity = lp.gravity;
    if (gravity == -1) {
        gravity = Gravity.TOP | Gravity.START;
    }

    int layoutDirection = 0;
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN)
        layoutDirection = getLayoutDirection();
    final int absoluteGravity = Gravity.getAbsoluteGravity(gravity, layoutDirection);
    final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;

    int childLeft;
    int childTop;
    switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.CENTER_HORIZONTAL:
            childLeft = (getWidth() + getPaddingLeft() - getPaddingRight()  - w) / 2 +
                    lp.leftMargin - lp.rightMargin;
            break;
        case Gravity.END:
            childLeft = getWidth() + getPaddingRight() - w - lp.rightMargin;
            break;
        case Gravity.START:
        default:
            childLeft = getPaddingLeft() + lp.leftMargin;
            break;
    }
    switch (verticalGravity) {
        case Gravity.CENTER_VERTICAL:
            childTop = (getHeight() + getPaddingTop() - getPaddingBottom()  - h) / 2 +
                    lp.topMargin - lp.bottomMargin;
            break;
        case Gravity.BOTTOM:
            childTop = getHeight() - getPaddingBottom() - h - lp.bottomMargin;
            break;
        case Gravity.TOP:
        default:
            childTop = getPaddingTop() + lp.topMargin;
            break;
    }
    child.layout(childLeft, childTop, childLeft + w, childTop + h);
    // 缩放层叠效果
    adjustChildView(child, index);
}
 
Example 17
Project: airgram   File: RecyclerView.java   Source Code and License Vote up 4 votes
/**
 * RecyclerView internally does its own View measurement caching which should help with
 * WRAP_CONTENT.
 * <p>
 * Use this method if the View is not yet measured and you need to decide whether to
 * measure this View or not.
 */
boolean shouldMeasureChild(View child, int widthSpec, int heightSpec, LayoutParams lp) {
    return child.isLayoutRequested()
            || !mMeasurementCacheEnabled
            || !isMeasurementUpToDate(child.getWidth(), widthSpec, lp.width)
            || !isMeasurementUpToDate(child.getHeight(), heightSpec, lp.height);
}
 
Example 18
Project: letv   File: RecyclerView.java   Source Code and License Vote up 4 votes
boolean shouldMeasureChild(View child, int widthSpec, int heightSpec, LayoutParams lp) {
    return (!child.isLayoutRequested() && this.mMeasurementCacheEnabled && isMeasurementUpToDate(child.getWidth(), widthSpec, lp.width) && isMeasurementUpToDate(child.getHeight(), heightSpec, lp.height)) ? false : true;
}
 
Example 19
Project: CustomAndroidOneSheeld   File: MultiDirectionSlidingDrawer.java   Source Code and License Vote up 4 votes
private void prepareContent() {
    if (mAnimating) {
        return;
    }

    // Something changed in the content, we need to honor the layout request
    // before creating the cached bitmap
    final View content = mContent;
    if (content.isLayoutRequested()) {

        if (mVertical) {
            final int handleHeight = mHandleHeight;
            int height = getBottom() - getTop() - handleHeight - mTopOffset;
            content.measure(MeasureSpec.makeMeasureSpec(getRight()
                    - getLeft(), MeasureSpec.EXACTLY), MeasureSpec
                    .makeMeasureSpec(height, MeasureSpec.EXACTLY));

            Log.d(LOG_TAG, "content.layout(2)");

            if (mInvert)
                content.layout(0, mTopOffset, content.getMeasuredWidth(),
                        mTopOffset + content.getMeasuredHeight());
            else
                content.layout(
                        0,
                        mTopOffset + handleHeight,
                        content.getMeasuredWidth(),
                        mTopOffset + handleHeight
                                + content.getMeasuredHeight());

        } else {

            final int handleWidth = mHandle.getWidth();
            int width = getRight() - getLeft() - handleWidth - mTopOffset;
            content.measure(MeasureSpec.makeMeasureSpec(width,
                    MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(
                    getBottom() - getTop(), MeasureSpec.EXACTLY));

            if (mInvert)
                content.layout(mTopOffset, 0,
                        mTopOffset + content.getMeasuredWidth(),
                        content.getMeasuredHeight());
            else
                content.layout(handleWidth + mTopOffset, 0, mTopOffset
                                + handleWidth + content.getMeasuredWidth(),
                        content.getMeasuredHeight());
        }
    }
    // Try only once... we should really loop but it's not a big deal
    // if the draw was cancelled, it will only be temporary anyway
    content.getViewTreeObserver().dispatchOnPreDraw();
    content.buildDrawingCache();

    content.setVisibility(View.GONE);
}
 
Example 20
Project: boohee_v5.6   File: RecyclerView.java   Source Code and License Vote up 4 votes
boolean shouldMeasureChild(View child, int widthSpec, int heightSpec, LayoutParams lp) {
    return (!child.isLayoutRequested() && this.mMeasurementCacheEnabled && isMeasurementUpToDate(child.getWidth(), widthSpec, lp.width) && isMeasurementUpToDate(child.getHeight(), heightSpec, lp.height)) ? false : true;
}