List of usage examples for android.view View getVisibility
@ViewDebug.ExportedProperty(mapping = { @ViewDebug.IntToString(from = VISIBLE, to = "VISIBLE"), @ViewDebug.IntToString(from = INVISIBLE, to = "INVISIBLE"), @ViewDebug.IntToString(from = GONE, to = "GONE") }) @Visibility public int getVisibility()
From source file:com.chenglong.muscle.ui.LazyViewPager.java
/** * We only want the current page that is being shown to be focusable. *///from w w w . j av a 2 s.co m @Override public void addFocusables(ArrayList<View> views, int direction, int focusableMode) { final int focusableCount = views.size(); final int descendantFocusability = getDescendantFocusability(); if (descendantFocusability != FOCUS_BLOCK_DESCENDANTS) { for (int i = 0; i < getChildCount(); i++) { final View child = getChildAt(i); if (child.getVisibility() == VISIBLE) { ItemInfo ii = infoForChild(child); if (ii != null && ii.position == mCurItem) { child.addFocusables(views, direction, focusableMode); } } } } // we add ourselves (if focusable) in all cases except for when we are // FOCUS_AFTER_DESCENDANTS and there are some descendants focusable. // this is // to avoid the focus search finding layouts when a more precise search // among the focusable children would be more interesting. if (descendantFocusability != FOCUS_AFTER_DESCENDANTS || // No focusable descendants (focusableCount == views.size())) { // Note that we can't call the superclass here, because it will // add all views in. So we need to do the same thing View does. if (!isFocusable()) { return; } if ((focusableMode & FOCUSABLES_TOUCH_MODE) == FOCUSABLES_TOUCH_MODE && isInTouchMode() && !isFocusableInTouchMode()) { return; } if (views != null) { views.add(this); } } }
From source file:cn.bingoogolapple.swipebacklayout.BGASwipeBackLayout.java
void updateObscuredViewsVisibility(View panel) { final boolean isLayoutRtl = isLayoutRtlSupport(); final int startBound = isLayoutRtl ? (getWidth() - getPaddingRight()) : getPaddingLeft(); final int endBound = isLayoutRtl ? getPaddingLeft() : (getWidth() - getPaddingRight()); final int topBound = getPaddingTop(); final int bottomBound = getHeight() - getPaddingBottom(); final int left; final int right; final int top; final int bottom; if (panel != null && viewIsOpaque(panel)) { left = panel.getLeft();/* ww w . java 2 s. c om*/ right = panel.getRight(); top = panel.getTop(); bottom = panel.getBottom(); } else { left = right = top = bottom = 0; } for (int i = 0, childCount = getChildCount(); i < childCount; i++) { final View child = getChildAt(i); if (child == panel) { // There are still more children above the panel but they won't be affected. break; } else if (child.getVisibility() == GONE) { continue; } final int clampedChildLeft = Math.max((isLayoutRtl ? endBound : startBound), child.getLeft()); final int clampedChildTop = Math.max(topBound, child.getTop()); final int clampedChildRight = Math.min((isLayoutRtl ? startBound : endBound), child.getRight()); final int clampedChildBottom = Math.min(bottomBound, child.getBottom()); final int vis; if (clampedChildLeft >= left && clampedChildTop >= top && clampedChildRight <= right && clampedChildBottom <= bottom) { vis = INVISIBLE; } else { vis = VISIBLE; } child.setVisibility(vis); } }
From source file:com.chenglong.muscle.ui.LazyViewPager.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // For simple implementation, or internal size is always 0. // We depend on the container to specify the layout size of // our view. We can't really know what it is since we will be // adding and removing different arbitrary views and do not // want the layout to change as this happens. setMeasuredDimension(getDefaultSize(0, widthMeasureSpec), getDefaultSize(0, heightMeasureSpec)); // Children are just made to fill our space. int childWidthSize = getMeasuredWidth() - getPaddingLeft() - getPaddingRight(); int childHeightSize = getMeasuredHeight() - getPaddingTop() - getPaddingBottom(); /*/* w w w. jav a2s. c om*/ * Make sure all children have been properly measured. Decor views * first. Right now we cheat and make this less complicated by assuming * decor views won't intersect. We will pin to edges based on gravity. */ int size = getChildCount(); for (int i = 0; i < size; ++i) { final View child = getChildAt(i); if (child.getVisibility() != GONE) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (lp != null && lp.isDecor) { final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK; final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK; Log.d(TAG, "gravity: " + lp.gravity + " hgrav: " + hgrav + " vgrav: " + vgrav); int widthMode = MeasureSpec.AT_MOST; int heightMode = MeasureSpec.AT_MOST; boolean consumeVertical = vgrav == Gravity.TOP || vgrav == Gravity.BOTTOM; boolean consumeHorizontal = hgrav == Gravity.LEFT || hgrav == Gravity.RIGHT; if (consumeVertical) { widthMode = MeasureSpec.EXACTLY; } else if (consumeHorizontal) { heightMode = MeasureSpec.EXACTLY; } final int widthSpec = MeasureSpec.makeMeasureSpec(childWidthSize, widthMode); final int heightSpec = MeasureSpec.makeMeasureSpec(childHeightSize, heightMode); child.measure(widthSpec, heightSpec); if (consumeVertical) { childHeightSize -= child.getMeasuredHeight(); } else if (consumeHorizontal) { childWidthSize -= child.getMeasuredWidth(); } } } } mChildWidthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidthSize, MeasureSpec.EXACTLY); mChildHeightMeasureSpec = MeasureSpec.makeMeasureSpec(childHeightSize, MeasureSpec.EXACTLY); // Make sure we have created all fragments that we need to have shown. mInLayout = true; populate(); mInLayout = false; // Page views next. size = getChildCount(); for (int i = 0; i < size; ++i) { final View child = getChildAt(i); if (child.getVisibility() != GONE) { if (DEBUG) Log.v(TAG, "Measuring #" + i + " " + child + ": " + mChildWidthMeasureSpec); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (lp == null || !lp.isDecor) { child.measure(mChildWidthMeasureSpec, mChildHeightMeasureSpec); } } } }
From source file:com.chenglong.muscle.ui.LazyViewPager.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { mInLayout = true;/* w ww . java2 s.c om*/ populate(); mInLayout = false; final int count = getChildCount(); int width = r - l; int height = b - t; int paddingLeft = getPaddingLeft(); int paddingTop = getPaddingTop(); int paddingRight = getPaddingRight(); int paddingBottom = getPaddingBottom(); final int scrollX = getScrollX(); int decorCount = 0; for (int i = 0; i < count; i++) { final View child = getChildAt(i); if (child.getVisibility() != GONE) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); ItemInfo ii; int childLeft = 0; int childTop = 0; if (lp.isDecor) { final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK; final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK; switch (hgrav) { default: childLeft = paddingLeft; break; case Gravity.LEFT: childLeft = paddingLeft; paddingLeft += child.getMeasuredWidth(); break; case Gravity.CENTER_HORIZONTAL: childLeft = Math.max((width - child.getMeasuredWidth()) / 2, paddingLeft); break; case Gravity.RIGHT: childLeft = width - paddingRight - child.getMeasuredWidth(); paddingRight += child.getMeasuredWidth(); break; } switch (vgrav) { default: childTop = paddingTop; break; case Gravity.TOP: childTop = paddingTop; paddingTop += child.getMeasuredHeight(); break; case Gravity.CENTER_VERTICAL: childTop = Math.max((height - child.getMeasuredHeight()) / 2, paddingTop); break; case Gravity.BOTTOM: childTop = height - paddingBottom - child.getMeasuredHeight(); paddingBottom += child.getMeasuredHeight(); break; } childLeft += scrollX; decorCount++; child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(), childTop + child.getMeasuredHeight()); } else if ((ii = infoForChild(child)) != null) { int loff = (width + mPageMargin) * ii.position; childLeft = paddingLeft + loff; childTop = paddingTop; if (DEBUG) Log.v(TAG, "Positioning #" + i + " " + child + " f=" + ii.object + ":" + childLeft + "," + childTop + " " + child.getMeasuredWidth() + "x" + child.getMeasuredHeight()); child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(), childTop + child.getMeasuredHeight()); } } } mTopPageBounds = paddingTop; mBottomPageBounds = height - paddingBottom; mDecorChildCount = decorCount; mFirstLayout = false; }
From source file:com.aidy.bottomdrawerlayout.AllDrawerLayout.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { Log.i(TAG, "onMeasure -- widthMeasureSpec = " + widthMeasureSpec + " -- heightMeasureSpec = " + heightMeasureSpec);/*from w w w. j a v a 2 s . c om*/ int widthMode = MeasureSpec.getMode(widthMeasureSpec); int heightMode = MeasureSpec.getMode(heightMeasureSpec); int widthSize = MeasureSpec.getSize(widthMeasureSpec); int heightSize = MeasureSpec.getSize(heightMeasureSpec); if (widthMode != MeasureSpec.EXACTLY || heightMode != MeasureSpec.EXACTLY) { if (isInEditMode()) { if (widthMode == MeasureSpec.AT_MOST) { widthMode = MeasureSpec.EXACTLY; } else if (widthMode == MeasureSpec.UNSPECIFIED) { widthMode = MeasureSpec.EXACTLY; widthSize = 300; } if (heightMode == MeasureSpec.AT_MOST) { heightMode = MeasureSpec.EXACTLY; } else if (heightMode == MeasureSpec.UNSPECIFIED) { heightMode = MeasureSpec.EXACTLY; heightSize = 300; } } else { throw new IllegalArgumentException("DrawerLayout must be measured with MeasureSpec.EXACTLY."); } } setMeasuredDimension(widthSize, heightSize); // Gravity value for each drawer we've seen. Only one of each permitted. int foundDrawers = 0; final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); if (child.getVisibility() == GONE) { continue; } final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (isContentView(child)) { // Content views get measured at exactly the layout's size. final int contentWidthSpec = MeasureSpec.makeMeasureSpec(widthSize - lp.leftMargin - lp.rightMargin, MeasureSpec.EXACTLY); final int contentHeightSpec = MeasureSpec .makeMeasureSpec(heightSize - lp.topMargin - lp.bottomMargin, MeasureSpec.EXACTLY); child.measure(contentWidthSpec, contentHeightSpec); } else if (isDrawerView(child)) { final int childGravity = getDrawerViewAbsoluteGravity(child) & Gravity.HORIZONTAL_GRAVITY_MASK; if ((foundDrawers & childGravity) != 0) { throw new IllegalStateException( "Child drawer has absolute gravity " + gravityToString(childGravity) + " but this " + TAG + " already has a " + "drawer view along that edge"); } final int drawerWidthSpec = getChildMeasureSpec(widthMeasureSpec, mMinDrawerMargin + lp.leftMargin + lp.rightMargin, lp.width); final int drawerHeightSpec = getChildMeasureSpec(heightMeasureSpec, mMinDrawerMargin + lp.topMargin + lp.bottomMargin, lp.height); child.measure(drawerWidthSpec, drawerHeightSpec); } else { throw new IllegalStateException("Child " + child + " at index " + i + " does not have a valid layout_gravity - must be Gravity.LEFT, " + "Gravity.RIGHT or Gravity.NO_GRAVITY"); } } }
From source file:com.canace.mybaby.view.ImageViewPager.java
@Override public void addView(View child, int index, LayoutParams params) { if (mInLayout) { addViewInLayout(child, index, params); child.measure(mChildWidthMeasureSpec, mChildHeightMeasureSpec); } else {// w ww .j av a 2 s . c om super.addView(child, index, params); } if (USE_CACHE) { if (child.getVisibility() != GONE) { child.setDrawingCacheEnabled(mScrollingCacheEnabled); } else { child.setDrawingCacheEnabled(false); } } }
From source file:com.google.android.flexbox.FlexboxHelper.java
/** * Shrink the flex items along the main axis based on the individual mFlexShrink attribute. * * @param widthMeasureSpec the horizontal space requirements as imposed by the parent * @param heightMeasureSpec the vertical space requirements as imposed by the parent * @param flexLine the flex line to which flex items belong * @param maxMainSize the maximum main size. Shrank main size will be this size * @param paddingAlongMainAxis the padding value along the main axis * @param calledRecursively true if this method is called recursively, false otherwise * @see FlexContainer#getFlexDirection() * @see FlexContainer#setFlexDirection(int) * @see FlexItem#getFlexShrink()/*w w w . j av a2 s . c o m*/ */ private void shrinkFlexItems(int widthMeasureSpec, int heightMeasureSpec, FlexLine flexLine, int maxMainSize, int paddingAlongMainAxis, boolean calledRecursively) { int sizeBeforeShrink = flexLine.mMainSize; if (flexLine.mTotalFlexShrink <= 0 || maxMainSize > flexLine.mMainSize) { return; } boolean needsReshrink = false; float unitShrink = (flexLine.mMainSize - maxMainSize) / flexLine.mTotalFlexShrink; float accumulatedRoundError = 0; flexLine.mMainSize = paddingAlongMainAxis + flexLine.mDividerLengthInMainSize; // Setting the cross size of the flex line as the temporal value since the cross size of // each flex item may be changed from the initial calculation // (in the measureHorizontal/measureVertical method) even this method is part of the main // size determination. // E.g. If a TextView's layout_width is set to 0dp, layout_height is set to wrap_content, // and layout_flexGrow is set to 1, the TextView is trying to expand to the vertical // direction to enclose its content (in the measureHorizontal method), but // the width will be expanded in this method. In that case, the height needs to be measured // again with the expanded width. int largestCrossSize = 0; if (!calledRecursively) { flexLine.mCrossSize = Integer.MIN_VALUE; } for (int i = 0; i < flexLine.mItemCount; i++) { int index = flexLine.mFirstIndex + i; View child = mFlexContainer.getReorderedFlexItemAt(index); if (child == null || child.getVisibility() == View.GONE) { continue; } FlexItem flexItem = (FlexItem) child.getLayoutParams(); int flexDirection = mFlexContainer.getFlexDirection(); if (flexDirection == FlexDirection.ROW || flexDirection == FlexDirection.ROW_REVERSE) { // The direction of main axis is horizontal int childMeasuredWidth = child.getMeasuredWidth(); if (mMeasuredSizeCache != null) { // Retrieve the measured width from the cache because there // are some cases that the view is re-created from the last measure, thus // View#getMeasuredWidth returns 0. // E.g. if the flex container is FlexboxLayoutManager, the case happens // frequently childMeasuredWidth = extractLowerInt(mMeasuredSizeCache[index]); } int childMeasuredHeight = child.getMeasuredHeight(); if (mMeasuredSizeCache != null) { // Extract the measured height from the cache childMeasuredHeight = extractHigherInt(mMeasuredSizeCache[index]); } if (!mChildrenFrozen[index] && flexItem.getFlexShrink() > 0f) { float rawCalculatedWidth = childMeasuredWidth - unitShrink * flexItem.getFlexShrink(); if (i == flexLine.mItemCount - 1) { rawCalculatedWidth += accumulatedRoundError; accumulatedRoundError = 0; } int newWidth = Math.round(rawCalculatedWidth); if (newWidth < flexItem.getMinWidth()) { // This means the child doesn't have enough space to distribute the negative // free space. To adjust the flex line length down to the maxMainSize, // remaining // negative free space needs to be re-distributed to other flex items // (children views). In that case, invoke this method again with the same // fromIndex. needsReshrink = true; newWidth = flexItem.getMinWidth(); mChildrenFrozen[index] = true; flexLine.mTotalFlexShrink -= flexItem.getFlexShrink(); } else { accumulatedRoundError += (rawCalculatedWidth - newWidth); if (accumulatedRoundError > 1.0) { newWidth += 1; accumulatedRoundError -= 1; } else if (accumulatedRoundError < -1.0) { newWidth -= 1; accumulatedRoundError += 1; } } int childHeightMeasureSpec = getChildHeightMeasureSpecInternal(heightMeasureSpec, flexItem, flexLine.mSumCrossSizeBefore); int childWidthMeasureSpec = View.MeasureSpec.makeMeasureSpec(newWidth, View.MeasureSpec.EXACTLY); child.measure(childWidthMeasureSpec, childHeightMeasureSpec); childMeasuredWidth = child.getMeasuredWidth(); childMeasuredHeight = child.getMeasuredHeight(); updateMeasureCache(index, childWidthMeasureSpec, childHeightMeasureSpec, child); mFlexContainer.updateViewCache(index, child); } largestCrossSize = Math.max(largestCrossSize, childMeasuredHeight + flexItem.getMarginTop() + flexItem.getMarginBottom() + mFlexContainer.getDecorationLengthCrossAxis(child)); flexLine.mMainSize += childMeasuredWidth + flexItem.getMarginLeft() + flexItem.getMarginRight(); } else { // The direction of main axis is vertical int childMeasuredHeight = child.getMeasuredHeight(); if (mMeasuredSizeCache != null) { // Retrieve the measured height from the cache because there // are some cases that the view is re-created from the last measure, thus // View#getMeasuredHeight returns 0. // E.g. if the flex container is FlexboxLayoutManager, that case happens // frequently childMeasuredHeight = extractHigherInt(mMeasuredSizeCache[index]); } int childMeasuredWidth = child.getMeasuredWidth(); if (mMeasuredSizeCache != null) { // Extract the measured width from the cache childMeasuredWidth = extractLowerInt(mMeasuredSizeCache[index]); } if (!mChildrenFrozen[index] && flexItem.getFlexShrink() > 0f) { float rawCalculatedHeight = childMeasuredHeight - unitShrink * flexItem.getFlexShrink(); if (i == flexLine.mItemCount - 1) { rawCalculatedHeight += accumulatedRoundError; accumulatedRoundError = 0; } int newHeight = Math.round(rawCalculatedHeight); if (newHeight < flexItem.getMinHeight()) { // Need to invoke this method again like the case flex direction is vertical needsReshrink = true; newHeight = flexItem.getMinHeight(); mChildrenFrozen[index] = true; flexLine.mTotalFlexShrink -= flexItem.getFlexShrink(); } else { accumulatedRoundError += (rawCalculatedHeight - newHeight); if (accumulatedRoundError > 1.0) { newHeight += 1; accumulatedRoundError -= 1; } else if (accumulatedRoundError < -1.0) { newHeight -= 1; accumulatedRoundError += 1; } } int childWidthMeasureSpec = getChildWidthMeasureSpecInternal(widthMeasureSpec, flexItem, flexLine.mSumCrossSizeBefore); int childHeightMeasureSpec = View.MeasureSpec.makeMeasureSpec(newHeight, View.MeasureSpec.EXACTLY); child.measure(childWidthMeasureSpec, childHeightMeasureSpec); childMeasuredWidth = child.getMeasuredWidth(); childMeasuredHeight = child.getMeasuredHeight(); updateMeasureCache(index, childWidthMeasureSpec, childHeightMeasureSpec, child); mFlexContainer.updateViewCache(index, child); } largestCrossSize = Math.max(largestCrossSize, childMeasuredWidth + flexItem.getMarginLeft() + flexItem.getMarginRight() + mFlexContainer.getDecorationLengthCrossAxis(child)); flexLine.mMainSize += childMeasuredHeight + flexItem.getMarginTop() + flexItem.getMarginBottom(); } flexLine.mCrossSize = Math.max(flexLine.mCrossSize, largestCrossSize); } if (needsReshrink && sizeBeforeShrink != flexLine.mMainSize) { // Re-invoke the method with the same fromIndex to distribute the negative free space // that wasn't fully distributed (because some views length were not enough) shrinkFlexItems(widthMeasureSpec, heightMeasureSpec, flexLine, maxMainSize, paddingAlongMainAxis, true); } }
From source file:com.google.android.flexbox.FlexboxHelper.java
/** * Expand the flex items along the main axis based on the individual mFlexGrow attribute. * * @param widthMeasureSpec the horizontal space requirements as imposed by the parent * @param heightMeasureSpec the vertical space requirements as imposed by the parent * @param flexLine the flex line to which flex items belong * @param maxMainSize the maximum main size. Expanded main size will be this size * @param paddingAlongMainAxis the padding value along the main axis * @param calledRecursively true if this method is called recursively, false otherwise * @see FlexContainer#getFlexDirection() * @see FlexContainer#setFlexDirection(int) * @see FlexItem#getFlexGrow()/* ww w .j a v a 2 s . co m*/ */ private void expandFlexItems(int widthMeasureSpec, int heightMeasureSpec, FlexLine flexLine, int maxMainSize, int paddingAlongMainAxis, boolean calledRecursively) { if (flexLine.mTotalFlexGrow <= 0 || maxMainSize < flexLine.mMainSize) { return; } int sizeBeforeExpand = flexLine.mMainSize; boolean needsReexpand = false; float unitSpace = (maxMainSize - flexLine.mMainSize) / flexLine.mTotalFlexGrow; flexLine.mMainSize = paddingAlongMainAxis + flexLine.mDividerLengthInMainSize; // Setting the cross size of the flex line as the temporal value since the cross size of // each flex item may be changed from the initial calculation // (in the measureHorizontal/measureVertical method) even this method is part of the main // size determination. // E.g. If a TextView's layout_width is set to 0dp, layout_height is set to wrap_content, // and layout_flexGrow is set to 1, the TextView is trying to expand to the vertical // direction to enclose its content (in the measureHorizontal method), but // the width will be expanded in this method. In that case, the height needs to be measured // again with the expanded width. int largestCrossSize = 0; if (!calledRecursively) { flexLine.mCrossSize = Integer.MIN_VALUE; } float accumulatedRoundError = 0; for (int i = 0; i < flexLine.mItemCount; i++) { int index = flexLine.mFirstIndex + i; View child = mFlexContainer.getReorderedFlexItemAt(index); if (child == null || child.getVisibility() == View.GONE) { continue; } FlexItem flexItem = (FlexItem) child.getLayoutParams(); int flexDirection = mFlexContainer.getFlexDirection(); if (flexDirection == FlexDirection.ROW || flexDirection == FlexDirection.ROW_REVERSE) { // The direction of the main axis is horizontal int childMeasuredWidth = child.getMeasuredWidth(); if (mMeasuredSizeCache != null) { // Retrieve the measured width from the cache because there // are some cases that the view is re-created from the last measure, thus // View#getMeasuredWidth returns 0. // E.g. if the flex container is FlexboxLayoutManager, the case happens // frequently childMeasuredWidth = extractLowerInt(mMeasuredSizeCache[index]); } int childMeasuredHeight = child.getMeasuredHeight(); if (mMeasuredSizeCache != null) { // Extract the measured height from the cache childMeasuredHeight = extractHigherInt(mMeasuredSizeCache[index]); } if (!mChildrenFrozen[index] && flexItem.getFlexGrow() > 0f) { float rawCalculatedWidth = childMeasuredWidth + unitSpace * flexItem.getFlexGrow(); if (i == flexLine.mItemCount - 1) { rawCalculatedWidth += accumulatedRoundError; accumulatedRoundError = 0; } int newWidth = Math.round(rawCalculatedWidth); if (newWidth > flexItem.getMaxWidth()) { // This means the child can't expand beyond the value of the mMaxWidth // attribute. // To adjust the flex line length to the size of maxMainSize, remaining // positive free space needs to be re-distributed to other flex items // (children views). In that case, invoke this method again with the same // fromIndex. needsReexpand = true; newWidth = flexItem.getMaxWidth(); mChildrenFrozen[index] = true; flexLine.mTotalFlexGrow -= flexItem.getFlexGrow(); } else { accumulatedRoundError += (rawCalculatedWidth - newWidth); if (accumulatedRoundError > 1.0) { newWidth += 1; accumulatedRoundError -= 1.0; } else if (accumulatedRoundError < -1.0) { newWidth -= 1; accumulatedRoundError += 1.0; } } int childHeightMeasureSpec = getChildHeightMeasureSpecInternal(heightMeasureSpec, flexItem, flexLine.mSumCrossSizeBefore); int childWidthMeasureSpec = View.MeasureSpec.makeMeasureSpec(newWidth, View.MeasureSpec.EXACTLY); child.measure(childWidthMeasureSpec, childHeightMeasureSpec); childMeasuredWidth = child.getMeasuredWidth(); childMeasuredHeight = child.getMeasuredHeight(); updateMeasureCache(index, childWidthMeasureSpec, childHeightMeasureSpec, child); mFlexContainer.updateViewCache(index, child); } largestCrossSize = Math.max(largestCrossSize, childMeasuredHeight + flexItem.getMarginTop() + flexItem.getMarginBottom() + mFlexContainer.getDecorationLengthCrossAxis(child)); flexLine.mMainSize += childMeasuredWidth + flexItem.getMarginLeft() + flexItem.getMarginRight(); } else { // The direction of the main axis is vertical int childMeasuredHeight = child.getMeasuredHeight(); if (mMeasuredSizeCache != null) { // Retrieve the measured height from the cache because there // are some cases that the view is re-created from the last measure, thus // View#getMeasuredHeight returns 0. // E.g. if the flex container is FlexboxLayoutManager, that case happens // frequently childMeasuredHeight = extractHigherInt(mMeasuredSizeCache[index]); } int childMeasuredWidth = child.getMeasuredWidth(); if (mMeasuredSizeCache != null) { // Extract the measured width from the cache childMeasuredWidth = extractLowerInt(mMeasuredSizeCache[index]); } if (!mChildrenFrozen[index] && flexItem.getFlexGrow() > 0f) { float rawCalculatedHeight = childMeasuredHeight + unitSpace * flexItem.getFlexGrow(); if (i == flexLine.mItemCount - 1) { rawCalculatedHeight += accumulatedRoundError; accumulatedRoundError = 0; } int newHeight = Math.round(rawCalculatedHeight); if (newHeight > flexItem.getMaxHeight()) { // This means the child can't expand beyond the value of the mMaxHeight // attribute. // To adjust the flex line length to the size of maxMainSize, remaining // positive free space needs to be re-distributed to other flex items // (children views). In that case, invoke this method again with the same // fromIndex. needsReexpand = true; newHeight = flexItem.getMaxHeight(); mChildrenFrozen[index] = true; flexLine.mTotalFlexGrow -= flexItem.getFlexGrow(); } else { accumulatedRoundError += (rawCalculatedHeight - newHeight); if (accumulatedRoundError > 1.0) { newHeight += 1; accumulatedRoundError -= 1.0; } else if (accumulatedRoundError < -1.0) { newHeight -= 1; accumulatedRoundError += 1.0; } } int childWidthMeasureSpec = getChildWidthMeasureSpecInternal(widthMeasureSpec, flexItem, flexLine.mSumCrossSizeBefore); int childHeightMeasureSpec = View.MeasureSpec.makeMeasureSpec(newHeight, View.MeasureSpec.EXACTLY); child.measure(childWidthMeasureSpec, childHeightMeasureSpec); childMeasuredWidth = child.getMeasuredWidth(); childMeasuredHeight = child.getMeasuredHeight(); updateMeasureCache(index, childWidthMeasureSpec, childHeightMeasureSpec, child); mFlexContainer.updateViewCache(index, child); } largestCrossSize = Math.max(largestCrossSize, childMeasuredWidth + flexItem.getMarginLeft() + flexItem.getMarginRight() + mFlexContainer.getDecorationLengthCrossAxis(child)); flexLine.mMainSize += childMeasuredHeight + flexItem.getMarginTop() + flexItem.getMarginBottom(); } flexLine.mCrossSize = Math.max(flexLine.mCrossSize, largestCrossSize); } if (needsReexpand && sizeBeforeExpand != flexLine.mMainSize) { // Re-invoke the method with the same flex line to distribute the positive free space // that wasn't fully distributed (because of maximum length constraint) expandFlexItems(widthMeasureSpec, heightMeasureSpec, flexLine, maxMainSize, paddingAlongMainAxis, true); } }
From source file:com.aidy.bottomdrawerlayout.AllDrawerLayout.java
/** * 12-03 22:59:19.686: I/BottomDrawerLayout(12480): onLayout() -- left = 0 * -- top = 0 -- right = 1080 -- b = 1675 12-03 22:59:19.686: * I/BottomDrawerLayout(12480): onLayout() -- childWidth = 750 -- * childHeight = 1675 -- lp.onScreen = 0.0 12-03 22:59:19.686: * I/BottomDrawerLayout(12480): onLayout() -- childLeft = -750 -- newOffset * = 0.0 12-03 22:59:19.686: I/BottomDrawerLayout(12480): onLayout() -- * childWidth = 750 -- childHeight = 1675 -- lp.onScreen = 0.0 12-03 * 22:59:19.686: I/BottomDrawerLayout(12480): onLayout() -- childLeft = 1080 * -- newOffset = 0.0/*from ww w. j ava 2 s . com*/ */ @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { Log.i(TAG, "onLayout() -- left = " + l + " -- top = " + t + " -- right = " + r + " -- b = " + b); mInLayout = true; final int width = r - l;// final int height = b - t;// final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); if (child.getVisibility() == GONE) { continue; } final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (isContentView(child)) { child.layout(lp.leftMargin, lp.topMargin, lp.leftMargin + child.getMeasuredWidth(), lp.topMargin + child.getMeasuredHeight()); } else { // ?view final int childWidth = child.getMeasuredWidth(); final int childHeight = child.getMeasuredHeight(); // Log.i(TAG, "onLayout() -- childWidth = " + childWidth + // " -- childHeight = " + childHeight // + " -- lp.onScreen = " + lp.onScreen); int childLeft = 0;// int childTop = 0;// float newOffset = 0;// switch (getDrawerViewAbsoluteGravity(child)) { case Gravity.LEFT: if (checkDrawerViewAbsoluteGravity(child, Gravity.LEFT)) { // Log.i(TAG, "onLayout() -- 1"); childLeft = -childWidth + (int) (childWidth * lp.onScreen); newOffset = (float) (childWidth + childLeft) / childWidth;// ? } break; case Gravity.RIGHT: if (checkDrawerViewAbsoluteGravity(child, Gravity.RIGHT)) { // Log.i(TAG, "onLayout() -- 2"); childLeft = width - (int) (childWidth * lp.onScreen); newOffset = (float) (width - childLeft) / childWidth;// ? } break; case Gravity.TOP: if (checkDrawerViewAbsoluteGravity(child, Gravity.TOP)) { // Log.i(TAG, "onLayout() -- 3"); childTop = -childHeight + (int) (childHeight * lp.onScreen); newOffset = (float) (childHeight + childTop) / childHeight;// ? } break; case Gravity.BOTTOM: if (checkDrawerViewAbsoluteGravity(child, Gravity.BOTTOM)) { // Log.i(TAG, "onLayout() -- 4"); childTop = height - (int) (childHeight * lp.onScreen); newOffset = (float) (height - childTop) / childHeight;// ? } break; default: childTop = height - (int) (childHeight * lp.onScreen); newOffset = (float) (height - childTop) / childHeight;// ? break; } // ///////////////////////////////////////// // Log.i(TAG, "onLayout() -- childLeft = " + childLeft + // " -- newOffset = " + newOffset); final boolean changeOffset = newOffset != lp.onScreen; final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK; switch (vgrav) { // case Gravity.TOP: { // Log.i(TAG, "onLayout() -- Gravity.TOP"); // child.layout(childLeft, lp.topMargin, childLeft + childWidth, // lp.topMargin + childHeight); // break; // } // case Gravity.BOTTOM: { // Log.i(TAG, "onLayout() -- Gravity.BOTTOM"); // child.layout(childLeft, height - lp.bottomMargin - // child.getMeasuredHeight(), childLeft // + childWidth, height - lp.bottomMargin); // break; // } case Gravity.CENTER_VERTICAL: { // Log.i(TAG, "onLayout() -- Gravity.CENTER_VERTICAL"); int childTop_cv = (height - childHeight) / 2; // Offset for margins. If things don't fit right because of // bad measurement before, oh well. if (childTop_cv < lp.topMargin) { childTop_cv = lp.topMargin; } else if (childTop_cv + childHeight > height - lp.bottomMargin) { childTop_cv = height - lp.bottomMargin - childHeight; } child.layout(childLeft, childTop_cv, childLeft + childWidth, childTop_cv + childHeight); break; } } // ///////////////////////////////////////// if (changeOffset) { setDrawerViewOffset(child, newOffset); } final int newVisibility = lp.onScreen > 0 ? VISIBLE : INVISIBLE; if (child.getVisibility() != newVisibility) { child.setVisibility(newVisibility); } } } mInLayout = false; mFirstLayout = false; }
From source file:cn.bingoogolapple.swipebacklayout.BGASwipeBackLayout.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int widthMode = MeasureSpec.getMode(widthMeasureSpec); int widthSize = MeasureSpec.getSize(widthMeasureSpec); int heightMode = MeasureSpec.getMode(heightMeasureSpec); int heightSize = MeasureSpec.getSize(heightMeasureSpec); if (widthMode != MeasureSpec.EXACTLY) { if (isInEditMode()) { // Don't crash the layout editor. Consume all of the space if specified // or pick a magic number from thin air otherwise. // TODO Better communication with tools of this bogus state. // It will crash on a real device. if (widthMode == MeasureSpec.AT_MOST) { widthMode = MeasureSpec.EXACTLY; } else if (widthMode == MeasureSpec.UNSPECIFIED) { widthMode = MeasureSpec.EXACTLY; widthSize = 300;/*from w ww. jav a 2s.c o m*/ } } else { throw new IllegalStateException("Width must have an exact value or MATCH_PARENT"); } } else if (heightMode == MeasureSpec.UNSPECIFIED) { if (isInEditMode()) { // Don't crash the layout editor. Pick a magic number from thin air instead. // TODO Better communication with tools of this bogus state. // It will crash on a real device. if (heightMode == MeasureSpec.UNSPECIFIED) { heightMode = MeasureSpec.AT_MOST; heightSize = 300; } } else { throw new IllegalStateException("Height must not be UNSPECIFIED"); } } int layoutHeight = 0; int maxLayoutHeight = -1; switch (heightMode) { case MeasureSpec.EXACTLY: layoutHeight = maxLayoutHeight = heightSize - getPaddingTop() - getPaddingBottom(); break; case MeasureSpec.AT_MOST: maxLayoutHeight = heightSize - getPaddingTop() - getPaddingBottom(); break; } // ======================== START ======================== maxLayoutHeight -= UIUtil.getNavigationBarHeight(mActivity); // ======================== END ======================== float weightSum = 0; boolean canSlide = false; final int widthAvailable = widthSize - getPaddingLeft() - getPaddingRight(); int widthRemaining = widthAvailable; final int childCount = getChildCount(); if (childCount > 2) { Log.e(TAG, "onMeasure: More than two child views are not supported."); } // We'll find the current one below. mSlideableView = null; // First pass. Measure based on child LayoutParams width/height. // Weight will incur a second pass. for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (child.getVisibility() == GONE) { lp.dimWhenOffset = false; continue; } if (lp.weight > 0) { weightSum += lp.weight; // If we have no width, weight is the only contributor to the final size. // Measure this view on the weight pass only. if (lp.width == 0) continue; } int childWidthSpec; final int horizontalMargin = lp.leftMargin + lp.rightMargin; if (lp.width == LayoutParams.WRAP_CONTENT) { childWidthSpec = MeasureSpec.makeMeasureSpec(widthAvailable - horizontalMargin, MeasureSpec.AT_MOST); } else if (lp.width == LayoutParams.MATCH_PARENT) { childWidthSpec = MeasureSpec.makeMeasureSpec(widthAvailable - horizontalMargin, MeasureSpec.EXACTLY); } else { childWidthSpec = MeasureSpec.makeMeasureSpec(lp.width, MeasureSpec.EXACTLY); } int childHeightSpec; if (lp.height == LayoutParams.WRAP_CONTENT) { childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.AT_MOST); } else if (lp.height == LayoutParams.MATCH_PARENT) { childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.EXACTLY); } else { childHeightSpec = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY); } child.measure(childWidthSpec, childHeightSpec); final int childWidth = child.getMeasuredWidth(); final int childHeight = child.getMeasuredHeight(); if (heightMode == MeasureSpec.AT_MOST && childHeight > layoutHeight) { layoutHeight = Math.min(childHeight, maxLayoutHeight); } widthRemaining -= childWidth; canSlide |= lp.slideable = widthRemaining < 0; if (lp.slideable) { mSlideableView = child; } } // Resolve weight and make sure non-sliding panels are smaller than the full screen. if (canSlide || weightSum > 0) { final int fixedPanelWidthLimit = widthAvailable - mOverhangSize; for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); if (child.getVisibility() == GONE) { continue; } final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (child.getVisibility() == GONE) { continue; } final boolean skippedFirstPass = lp.width == 0 && lp.weight > 0; final int measuredWidth = skippedFirstPass ? 0 : child.getMeasuredWidth(); if (canSlide && child != mSlideableView) { if (lp.width < 0 && (measuredWidth > fixedPanelWidthLimit || lp.weight > 0)) { // Fixed panels in a sliding configuration should // be clamped to the fixed panel limit. final int childHeightSpec; if (skippedFirstPass) { // Do initial height measurement if we skipped measuring this view // the first time around. if (lp.height == LayoutParams.WRAP_CONTENT) { childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.AT_MOST); } else if (lp.height == LayoutParams.MATCH_PARENT) { childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.EXACTLY); } else { childHeightSpec = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY); } } else { childHeightSpec = MeasureSpec.makeMeasureSpec(child.getMeasuredHeight(), MeasureSpec.EXACTLY); } final int childWidthSpec = MeasureSpec.makeMeasureSpec(fixedPanelWidthLimit, MeasureSpec.EXACTLY); child.measure(childWidthSpec, childHeightSpec); } } else if (lp.weight > 0) { int childHeightSpec; if (lp.width == 0) { // This was skipped the first time; figure out a real height spec. if (lp.height == LayoutParams.WRAP_CONTENT) { childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.AT_MOST); } else if (lp.height == LayoutParams.MATCH_PARENT) { childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight, MeasureSpec.EXACTLY); } else { childHeightSpec = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY); } } else { childHeightSpec = MeasureSpec.makeMeasureSpec(child.getMeasuredHeight(), MeasureSpec.EXACTLY); } if (canSlide) { // Consume available space final int horizontalMargin = lp.leftMargin + lp.rightMargin; final int newWidth = widthAvailable - horizontalMargin; final int childWidthSpec = MeasureSpec.makeMeasureSpec(newWidth, MeasureSpec.EXACTLY); if (measuredWidth != newWidth) { child.measure(childWidthSpec, childHeightSpec); } } else { // Distribute the extra width proportionally similar to LinearLayout final int widthToDistribute = Math.max(0, widthRemaining); final int addedWidth = (int) (lp.weight * widthToDistribute / weightSum); final int childWidthSpec = MeasureSpec.makeMeasureSpec(measuredWidth + addedWidth, MeasureSpec.EXACTLY); child.measure(childWidthSpec, childHeightSpec); } } } } final int measuredWidth = widthSize; final int measuredHeight = layoutHeight + getPaddingTop() + getPaddingBottom(); setMeasuredDimension(measuredWidth, measuredHeight); mCanSlide = canSlide; if (mDragHelper.getViewDragState() != ViewDragHelper.STATE_IDLE && !canSlide) { // Cancel scrolling in progress, it's no longer relevant. mDragHelper.abort(); } }