List of usage examples for android.view View getLayoutParams
@ViewDebug.ExportedProperty(deepExport = true, prefix = "layout_") public ViewGroup.LayoutParams getLayoutParams()
From source file:android.support.v71.widget.LinearLayoutManager.java
void layoutChunk(RecyclerView.Recycler recycler, RecyclerView.State state, LayoutState layoutState, LayoutChunkResult result) {//from w w w. j av a 2 s.c om View view = layoutState.next(recycler); if (view == null) { if (DEBUG && layoutState.mScrapList == null) { throw new RuntimeException("received null view when unexpected"); } // if we are laying out views in scrap, this may return null which means there is // no more items to layout. result.mFinished = true; return; } LayoutParams params = (LayoutParams) view.getLayoutParams(); if (layoutState.mScrapList == null) { if (mShouldReverseLayout == (layoutState.mLayoutDirection == LayoutState.LAYOUT_START)) { addView(view); } else { addView(view, 0); } } else { if (mShouldReverseLayout == (layoutState.mLayoutDirection == LayoutState.LAYOUT_START)) { addDisappearingView(view); } else { addDisappearingView(view, 0); } } measureChildWithMargins(view, 0, 0); result.mConsumed = mOrientationHelper.getDecoratedMeasurement(view); int left, top, right, bottom; if (mOrientation == VERTICAL) { if (isLayoutRTL()) { right = getWidth() - getPaddingRight(); left = right - mOrientationHelper.getDecoratedMeasurementInOther(view); } else { left = getPaddingLeft(); right = left + mOrientationHelper.getDecoratedMeasurementInOther(view); } if (layoutState.mLayoutDirection == LayoutState.LAYOUT_START) { bottom = layoutState.mOffset; top = layoutState.mOffset - result.mConsumed; } else { top = layoutState.mOffset; bottom = layoutState.mOffset + result.mConsumed; } } else { top = getPaddingTop(); bottom = top + mOrientationHelper.getDecoratedMeasurementInOther(view); if (layoutState.mLayoutDirection == LayoutState.LAYOUT_START) { right = layoutState.mOffset; left = layoutState.mOffset - result.mConsumed; } else { left = layoutState.mOffset; right = layoutState.mOffset + result.mConsumed; } } // We calculate everything with View's bounding box (which includes decor and margins) // To calculate correct layout position, we subtract margins. // ? //TODO ?View ? layoutDecorated(view, left + params.leftMargin, top + params.topMargin, right - params.rightMargin, bottom - params.bottomMargin); if (DEBUG) { Log.d(TAG, "laid out child at position " + getPosition(view) + ", with l:" + (left + params.leftMargin) + ", t:" + (top + params.topMargin) + ", r:" + (right - params.rightMargin) + ", b:" + (bottom - params.bottomMargin)); } // Consume the available space if the view is not removed OR changed if (params.isItemRemoved() || params.isItemChanged()) { result.mIgnoreConsumed = true; } result.mFocusable = view.isFocusable(); }
From source file:android.support.v7.widget.StaggeredGridLayoutManager2.java
/** * Checks for gaps if we've reached to the top of the list. * <p>//from w w w . ja v a2 s . c o m * Intermediate gaps created by full span items are tracked via mLaidOutInvalidFullSpan field. */ View hasGapsToFix() { int startChildIndex = 0; int endChildIndex = getChildCount() - 1; BitSet mSpansToCheck = new BitSet(mSpanCount); mSpansToCheck.set(0, mSpanCount, true); final int firstChildIndex, childLimit; final int preferredSpanDir = mOrientation == VERTICAL && isLayoutRTL() ? 1 : -1; if (mShouldReverseLayout) { firstChildIndex = endChildIndex - 1; childLimit = startChildIndex - 1; } else { firstChildIndex = startChildIndex; childLimit = endChildIndex; } final int nextChildDiff = firstChildIndex < childLimit ? 1 : -1; for (int i = firstChildIndex; i != childLimit; i += nextChildDiff) { View child = getChildAt(i); LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (mSpansToCheck.get(lp.mSpan.mIndex)) { if (checkSpanForGap(lp.mSpan)) { return child; } mSpansToCheck.clear(lp.mSpan.mIndex); } if (lp.mFullSpan) { continue; // quick reject } if (i + nextChildDiff != childLimit) { View nextChild = getChildAt(i + nextChildDiff); boolean compareSpans = false; if (mShouldReverseLayout) { // ensure child's end is below nextChild's end int myEnd = mPrimaryOrientation.getDecoratedEnd(child); int nextEnd = mPrimaryOrientation.getDecoratedEnd(nextChild); if (myEnd < nextEnd) { return child;//i should have a better position } else if (myEnd == nextEnd) { compareSpans = true; } } else { int myStart = mPrimaryOrientation.getDecoratedStart(child); int nextStart = mPrimaryOrientation.getDecoratedStart(nextChild); if (myStart > nextStart) { return child;//i should have a better position } else if (myStart == nextStart) { compareSpans = true; } } if (compareSpans) { // equal, check span indices. LayoutParams nextLp = (LayoutParams) nextChild.getLayoutParams(); if (lp.mSpan.mIndex - nextLp.mSpan.mIndex < 0 != preferredSpanDir < 0) { return child; } } } } // everything looks good return null; }
From source file:android.support.v7.widget.StaggeredGridLayoutManager2.java
private void recycleFromStart(RecyclerView.Recycler recycler, int line) { if (DEBUG) {/*from ww w . j a v a 2 s.c om*/ Log.d(TAG, "recycling from start for line " + line); } while (getChildCount() > 0) { View child = getChildAt(0); if (mPrimaryOrientation.getDecoratedEnd(child) < line) { LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (lp.mFullSpan) { for (int j = 0; j < mSpanCount; j++) { mSpans[j].popStart(); } } else { lp.mSpan.popStart(); } removeAndRecycleView(child, recycler); } else { return;// done } } }
From source file:android.support.v7.widget.StaggeredGridLayoutManager2.java
private void recycleFromEnd(RecyclerView.Recycler recycler, int line) { final int childCount = getChildCount(); int i;/* w ww. ja v a 2 s . co m*/ for (i = childCount - 1; i >= 0; i--) { View child = getChildAt(i); if (mPrimaryOrientation.getDecoratedStart(child) > line) { LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (lp.mFullSpan) { for (int j = 0; j < mSpanCount; j++) { mSpans[j].popEnd(); } } else { lp.mSpan.popEnd(); } removeAndRecycleView(child, recycler); } else { return;// done } } }
From source file:android.support.v7.widget.StaggeredGridLayoutManager2.java
private void measureChildWithDecorationsAndMargin(View child, int widthSpec, int heightSpec) { final Rect insets = mRecyclerView.getItemDecorInsetsForChild(child); LayoutParams lp = (LayoutParams) child.getLayoutParams(); widthSpec = updateSpecWithExtra(widthSpec, lp.leftMargin + insets.left, lp.rightMargin + insets.right); heightSpec = updateSpecWithExtra(heightSpec, lp.topMargin + insets.top, lp.bottomMargin + insets.bottom); child.measure(widthSpec, heightSpec); }
From source file:android.support.designox.widget.CoordinatorLayout.java
/** * Check if the given child has any layout dependencies on other child views. *//*from ww w.j ava2s .c o m*/ boolean hasDependencies(View child) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (lp.mAnchorView != null) { return true; } final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View other = getChildAt(i); if (other == child) { continue; } if (lp.dependsOn(this, child, other)) { return true; } } return false; }
From source file:android.support.v7.widget.StaggeredGridLayoutManager2.java
private int fill(RecyclerView.Recycler recycler, LayoutState layoutState, RecyclerView.State state) { mRemainingSpans.set(0, mSpanCount, true); // The target position we are trying to reach. final int targetLine; /*/*ww w .j av a 2s . co m*/ * The line until which we can recycle, as long as we add views. * Keep in mind, it is still the line in layout direction which means; to calculate the * actual recycle line, we should subtract/add the size in orientation. */ final int recycleLine; // Line of the furthest row. if (layoutState.mLayoutDirection == LAYOUT_END) { // ignore padding for recycler recycleLine = mPrimaryOrientation.getEndAfterPadding() + mLayoutState.mAvailable; targetLine = recycleLine + mLayoutState.mExtra + mPrimaryOrientation.getEndPadding(); } else { // LAYOUT_START // ignore padding for recycler recycleLine = mPrimaryOrientation.getStartAfterPadding() - mLayoutState.mAvailable; targetLine = recycleLine - mLayoutState.mExtra - mPrimaryOrientation.getStartAfterPadding(); } updateAllRemainingSpans(layoutState.mLayoutDirection, targetLine); // the default coordinate to add new view. final int defaultNewViewLine = mShouldReverseLayout ? mPrimaryOrientation.getEndAfterPadding() : mPrimaryOrientation.getStartAfterPadding(); while (layoutState.hasMore(state) && !mRemainingSpans.isEmpty()) { View view = layoutState.next(recycler); LayoutParams lp = ((LayoutParams) view.getLayoutParams()); if (layoutState.mLayoutDirection == LAYOUT_END) { addView(view); } else { addView(view, 0); } final int position = lp.getViewPosition(); final int spanIndex = mLazySpanLookup.getSpan(position); Span currentSpan; boolean assignSpan = spanIndex == LayoutParams.INVALID_SPAN_ID; if (assignSpan) { currentSpan = lp.mFullSpan ? mSpans[0] : getNextSpan(layoutState); mLazySpanLookup.setSpan(position, currentSpan); if (DEBUG) { Log.d(TAG, "assigned " + currentSpan.mIndex + " for " + position); } } else { if (DEBUG) { Log.d(TAG, "using " + spanIndex + " for pos " + position); } currentSpan = mSpans[spanIndex]; } lp.mSpan = currentSpan; measureChildWithDecorationsAndMargin(view, lp); final int start; final int end; if (layoutState.mLayoutDirection == LAYOUT_END) { start = lp.mFullSpan ? getMaxEnd(defaultNewViewLine) : currentSpan.getEndLine(defaultNewViewLine); end = start + mPrimaryOrientation.getDecoratedMeasurement(view); if (assignSpan && lp.mFullSpan) { LazySpanLookup.FullSpanItem fullSpanItem; fullSpanItem = createFullSpanItemFromEnd(start); fullSpanItem.mGapDir = LAYOUT_START; fullSpanItem.mPosition = position; mLazySpanLookup.addFullSpanItem(fullSpanItem); } } else { end = lp.mFullSpan ? getMinStart(defaultNewViewLine) : currentSpan.getStartLine(defaultNewViewLine); start = end - mPrimaryOrientation.getDecoratedMeasurement(view); if (assignSpan && lp.mFullSpan) { LazySpanLookup.FullSpanItem fullSpanItem; fullSpanItem = createFullSpanItemFromStart(end); fullSpanItem.mGapDir = LAYOUT_END; fullSpanItem.mPosition = position; mLazySpanLookup.addFullSpanItem(fullSpanItem); } } // check if this item may create gaps in the future if (lp.mFullSpan && layoutState.mItemDirection == ITEM_DIRECTION_HEAD && assignSpan) { mLaidOutInvalidFullSpan = true; } attachViewToSpans(view, lp, layoutState); final int otherStart = lp.mFullSpan ? mSecondaryOrientation.getStartAfterPadding() : currentSpan.mIndex * mSizePerSpan + mSecondaryOrientation.getStartAfterPadding(); final int otherEnd = otherStart + mSecondaryOrientation.getDecoratedMeasurement(view); if (mOrientation == VERTICAL) { layoutDecoratedWithMargins(view, otherStart, start, otherEnd, end); } else { layoutDecoratedWithMargins(view, start, otherStart, end, otherEnd); } if (lp.mFullSpan) { updateAllRemainingSpans(mLayoutState.mLayoutDirection, targetLine); } else { updateRemainingSpans(currentSpan, mLayoutState.mLayoutDirection, targetLine); } recycle(recycler, mLayoutState, currentSpan, recycleLine); } if (DEBUG) { Log.d(TAG, "fill, " + getChildCount()); } if (mLayoutState.mLayoutDirection == LAYOUT_START) { final int minStart = getMinStart(mPrimaryOrientation.getStartAfterPadding()); return Math.max(0, mLayoutState.mAvailable + (recycleLine - minStart)); } else { final int max = getMaxEnd(mPrimaryOrientation.getEndAfterPadding()); return Math.max(0, mLayoutState.mAvailable + (max - recycleLine)); } }
From source file:com.taobao.weex.devtools.inspector.protocol.module.DOM.java
@ChromeDevtoolsMethod public GetBoxModelResponse getBoxModel(JsonRpcPeer peer, JSONObject params) { GetBoxModelResponse response = new GetBoxModelResponse(); final BoxModel model = new BoxModel(); final GetBoxModelRequest request = mObjectMapper.convertValue(params, GetBoxModelRequest.class); if (request.nodeId == null) { return null; }// w w w. j ava2s . c o m response.model = model; mDocument.postAndWait(new Runnable() { @Override public void run() { final Object elementForNodeId = mDocument.getElementForNodeId(request.nodeId); if (elementForNodeId == null) { LogUtil.w("Failed to get style of an element that does not exist, nodeid=" + request.nodeId); return; } mDocument.getElementStyles(elementForNodeId, new StyleAccumulator() { @Override public void store(String name, String value, boolean isDefault) { double left = 0; double right = 0; double top = 0; double bottom = 0; double paddingLeft = 0; double paddingRight = 0; double paddingTop = 0; double paddingBottom = 0; double marginLeft = 0; double marginRight = 0; double marginTop = 0; double marginBottom = 0; double borderLeftWidth = 0; double borderRightWidth = 0; double borderTopWidth = 0; double borderBottomWidth = 0; View view = null; if (isNativeMode()) { if (elementForNodeId instanceof View) { view = (View) elementForNodeId; } } else { if (elementForNodeId instanceof WXComponent) { view = ((WXComponent) elementForNodeId).getHostView(); } } if (view != null && view.isShown()) { float scale = ScreencastDispatcher.getsBitmapScale(); model.width = view.getWidth(); model.height = view.getHeight(); if (!DOM.isNativeMode()) { model.width = (int) (model.width * 750 / WXViewUtils.getScreenWidth() + 0.5); model.height = (int) (model.height * 750 / WXViewUtils.getScreenWidth() + 0.5); } int[] location = new int[2]; view.getLocationOnScreen(location); left = location[0] * scale; top = location[1] * scale; right = left + view.getWidth() * scale; bottom = top + view.getHeight() * scale; paddingLeft = view.getPaddingLeft() * scale; paddingTop = view.getPaddingTop() * scale; paddingRight = view.getPaddingRight() * scale; paddingBottom = view.getPaddingBottom() * scale; if (view instanceof ViewGroup) { ViewGroup.LayoutParams layoutParams = view.getLayoutParams(); if (layoutParams != null) { if (layoutParams instanceof ViewGroup.MarginLayoutParams) { ViewGroup.MarginLayoutParams margins = (ViewGroup.MarginLayoutParams) layoutParams; marginLeft = margins.leftMargin * scale; marginTop = margins.topMargin * scale; marginRight = margins.rightMargin * scale; marginBottom = margins.bottomMargin * scale; } } } } ArrayList<Double> padding = new ArrayList<>(8); padding.add(left + borderLeftWidth); padding.add(top + borderTopWidth); padding.add(right - borderRightWidth); padding.add(top + borderTopWidth); padding.add(right - borderRightWidth); padding.add(bottom - borderBottomWidth); padding.add(left + borderLeftWidth); padding.add(bottom - borderBottomWidth); model.padding = padding; ArrayList<Double> content = new ArrayList<>(8); content.add(left + borderLeftWidth + paddingLeft); content.add(top + borderTopWidth + paddingTop); content.add(right - borderRightWidth - paddingRight); content.add(top + borderTopWidth + paddingTop); content.add(right - borderRightWidth - paddingRight); content.add(bottom - borderBottomWidth - paddingBottom); content.add(left + borderLeftWidth + paddingLeft); content.add(bottom - borderBottomWidth - paddingBottom); model.content = content; ArrayList<Double> border = new ArrayList<>(8); border.add(left); border.add(top); border.add(right); border.add(top); border.add(right); border.add(bottom); border.add(left); border.add(bottom); model.border = border; ArrayList<Double> margin = new ArrayList<>(8); margin.add(left - marginLeft); margin.add(top - marginTop); margin.add(right + marginRight); margin.add(top - marginTop); margin.add(right + marginRight); margin.add(bottom + marginBottom); margin.add(left - marginLeft); margin.add(bottom + marginBottom); model.margin = margin; } }); } }); return response; }
From source file:android.support.designox.widget.CoordinatorLayout.java
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (lp.mBehavior != null && lp.mBehavior.getScrimOpacity(this, child) > 0.f) { if (mScrimPaint == null) { mScrimPaint = new Paint(); }//from ww w. j a va2 s. com mScrimPaint.setColor(lp.mBehavior.getScrimColor(this, child)); // TODO: Set the clip appropriately to avoid unnecessary overdraw. canvas.drawRect(getPaddingLeft(), getPaddingTop(), getWidth() - getPaddingRight(), getHeight() - getPaddingBottom(), mScrimPaint); } return super.drawChild(canvas, child, drawingTime); }
From source file:android.support.designox.widget.CoordinatorLayout.java
public boolean onNestedPreFling(View target, float velocityX, float velocityY) { boolean handled = false; final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View view = getChildAt(i); final LayoutParams lp = (LayoutParams) view.getLayoutParams(); if (!lp.isNestedScrollAccepted()) { continue; }/*from www . j a v a2 s .c o m*/ final Behavior viewBehavior = lp.getBehavior(); if (viewBehavior != null) { handled |= viewBehavior.onNestedPreFling(this, view, target, velocityX, velocityY); } } return handled; }