List of usage examples for android.view View getMeasuredHeight
public final int getMeasuredHeight()
From source file:com.aigo.kt03airdemo.ui.view.ResideLayout.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { mDragHelper.setEdgeTrackingEnabled(ViewDragHelper.EDGE_LEFT); final int width = r - l; final int paddingStart = getPaddingLeft(); final int paddingEnd = getPaddingRight(); final int paddingTop = getPaddingTop(); final int childCount = getChildCount(); int xStart = paddingStart; int nextXStart = xStart; if (mFirstLayout) { mSlideOffset = mCanSlide && mPreservedOpenState ? 1.f : 0.f; }/*from w w w . j a v a 2 s . com*/ for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); if (child.getVisibility() == GONE) { continue; } final LayoutParams lp = (LayoutParams) child.getLayoutParams(); final int childWidth = child.getMeasuredWidth(); int offset = 0; if (lp.slideable) { final int margin = lp.leftMargin + lp.rightMargin; final int range = Math.min(nextXStart, width - paddingEnd - mOverhangSize) - xStart - margin; mSlideRange = range; final int lpMargin = lp.leftMargin; lp.dimWhenOffset = xStart + lpMargin + range + childWidth / 2 > width - paddingEnd; final int pos = (int) (range * mSlideOffset); xStart += pos + lpMargin; mSlideOffset = (float) pos / mSlideRange; } else if (mCanSlide && mParallaxBy != 0) { offset = (int) ((1 - mSlideOffset) * mParallaxBy); xStart = nextXStart; } else { xStart = nextXStart; } final int childRight; final int childLeft; childLeft = xStart - offset; childRight = childLeft + childWidth; final int childBottom = paddingTop + child.getMeasuredHeight(); child.layout(childLeft, paddingTop, childRight, childBottom); nextXStart += child.getWidth(); } if (mFirstLayout) { if (mCanSlide) { if (mParallaxBy != 0) { parallaxOtherViews(mSlideOffset); } } updateObscuredViewsVisibility(mSlideableView); } mFirstLayout = false; }
From source file:com.csusm.twinder.Fragment.QRScanFragment.java
private void onCreateDetector(@NonNull final View view) { final Context context = view.getContext().getApplicationContext(); final BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(context).build(); barcodeDetector.setProcessor(new MultiProcessor.Builder<>(new MultiProcessor.Factory<Barcode>() { @Override/*from w w w .j a va 2 s.co m*/ public Tracker<Barcode> create(final Barcode barcode) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { mCallback.onScanComplete(barcode.displayValue); mPreview.stop(); Intent intent = new Intent(getContext(), ScanSuccessActivity.class); intent.putExtra("BARCODE", barcode.displayValue); QRScanFragment.this.startActivity(intent); } }); return new Tracker<>(); } }).build()); if (!barcodeDetector.isOperational()) { IntentFilter lowStorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW); if (context.registerReceiver(null, lowStorageFilter) != null) { // Low storage mCallback.onCameraError(R.string.camera_error_low_storage); } else { // Native libs unavailable mCallback.onCameraError(R.string.camera_error_dependencies); } return; } final ViewTreeObserver observer = view.getViewTreeObserver(); observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { view.getViewTreeObserver().removeGlobalOnLayoutListener(this); } else { view.getViewTreeObserver().removeOnGlobalLayoutListener(this); } CameraSource.Builder builder = new CameraSource.Builder(context, barcodeDetector) .setFacing(CameraSource.CAMERA_FACING_BACK) .setRequestedPreviewSize(view.getMeasuredWidth(), view.getMeasuredHeight()) .setRequestedFps(30.0f); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { builder = builder.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); } mCameraSource = builder.build(); startCameraSource(); } }); }
From source file:android.support.v7.widget.Toolbar.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int width = 0; int height = 0; int childState = 0; final int[] collapsingMargins = mTempMargins; final int marginStartIndex; final int marginEndIndex; if (ViewUtils.isLayoutRtl(this)) { marginStartIndex = 1;/*from w w w . j av a 2s .c om*/ marginEndIndex = 0; } else { marginStartIndex = 0; marginEndIndex = 1; } // System views measure first. int navWidth = 0; if (shouldLayout(mNavButtonView)) { measureChildConstrained(mNavButtonView, widthMeasureSpec, width, heightMeasureSpec, 0, mMaxButtonHeight); navWidth = mNavButtonView.getMeasuredWidth() + getHorizontalMargins(mNavButtonView); height = Math.max(height, mNavButtonView.getMeasuredHeight() + getVerticalMargins(mNavButtonView)); childState = ViewUtils.combineMeasuredStates(childState, ViewCompat.getMeasuredState(mNavButtonView)); } if (shouldLayout(mCollapseButtonView)) { measureChildConstrained(mCollapseButtonView, widthMeasureSpec, width, heightMeasureSpec, 0, mMaxButtonHeight); navWidth = mCollapseButtonView.getMeasuredWidth() + getHorizontalMargins(mCollapseButtonView); height = Math.max(height, mCollapseButtonView.getMeasuredHeight() + getVerticalMargins(mCollapseButtonView)); childState = ViewUtils.combineMeasuredStates(childState, ViewCompat.getMeasuredState(mCollapseButtonView)); } final int contentInsetStart = getContentInsetStart(); width += Math.max(contentInsetStart, navWidth); collapsingMargins[marginStartIndex] = Math.max(0, contentInsetStart - navWidth); int menuWidth = 0; if (shouldLayout(mMenuView)) { measureChildConstrained(mMenuView, widthMeasureSpec, width, heightMeasureSpec, 0, mMaxButtonHeight); menuWidth = mMenuView.getMeasuredWidth() + getHorizontalMargins(mMenuView); height = Math.max(height, mMenuView.getMeasuredHeight() + getVerticalMargins(mMenuView)); childState = ViewUtils.combineMeasuredStates(childState, ViewCompat.getMeasuredState(mMenuView)); } final int contentInsetEnd = getContentInsetEnd(); width += Math.max(contentInsetEnd, menuWidth); collapsingMargins[marginEndIndex] = Math.max(0, contentInsetEnd - menuWidth); if (shouldLayout(mExpandedActionView)) { width += measureChildCollapseMargins(mExpandedActionView, widthMeasureSpec, width, heightMeasureSpec, 0, collapsingMargins); height = Math.max(height, mExpandedActionView.getMeasuredHeight() + getVerticalMargins(mExpandedActionView)); childState = ViewUtils.combineMeasuredStates(childState, ViewCompat.getMeasuredState(mExpandedActionView)); } if (shouldLayout(mLogoView)) { width += measureChildCollapseMargins(mLogoView, widthMeasureSpec, width, heightMeasureSpec, 0, collapsingMargins); height = Math.max(height, mLogoView.getMeasuredHeight() + getVerticalMargins(mLogoView)); childState = ViewUtils.combineMeasuredStates(childState, ViewCompat.getMeasuredState(mLogoView)); } final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (lp.mViewType != LayoutParams.CUSTOM || !shouldLayout(child)) { // We already got all system views above. Skip them and GONE views. continue; } width += measureChildCollapseMargins(child, widthMeasureSpec, width, heightMeasureSpec, 0, collapsingMargins); height = Math.max(height, child.getMeasuredHeight() + getVerticalMargins(child)); childState = ViewUtils.combineMeasuredStates(childState, ViewCompat.getMeasuredState(child)); } int titleWidth = 0; int titleHeight = 0; final int titleVertMargins = mTitleMarginTop + mTitleMarginBottom; final int titleHorizMargins = mTitleMarginStart + mTitleMarginEnd; if (shouldLayout(mTitleTextView)) { titleWidth = measureChildCollapseMargins(mTitleTextView, widthMeasureSpec, width + titleHorizMargins, heightMeasureSpec, titleVertMargins, collapsingMargins); titleWidth = mTitleTextView.getMeasuredWidth() + getHorizontalMargins(mTitleTextView); titleHeight = mTitleTextView.getMeasuredHeight() + getVerticalMargins(mTitleTextView); childState = ViewUtils.combineMeasuredStates(childState, ViewCompat.getMeasuredState(mTitleTextView)); } if (shouldLayout(mSubtitleTextView)) { titleWidth = Math.max(titleWidth, measureChildCollapseMargins(mSubtitleTextView, widthMeasureSpec, width + titleHorizMargins, heightMeasureSpec, titleHeight + titleVertMargins, collapsingMargins)); titleHeight += mSubtitleTextView.getMeasuredHeight() + getVerticalMargins(mSubtitleTextView); childState = ViewUtils.combineMeasuredStates(childState, ViewCompat.getMeasuredState(mSubtitleTextView)); } width += titleWidth; height = Math.max(height, titleHeight); // Measurement already took padding into account for available space for the children, // add it in for the final size. width += getPaddingLeft() + getPaddingRight(); height += getPaddingTop() + getPaddingBottom(); final int measuredWidth = ViewCompat.resolveSizeAndState(Math.max(width, getSuggestedMinimumWidth()), widthMeasureSpec, childState & ViewCompat.MEASURED_STATE_MASK); final int measuredHeight = ViewCompat.resolveSizeAndState(Math.max(height, getSuggestedMinimumHeight()), heightMeasureSpec, childState << ViewCompat.MEASURED_HEIGHT_STATE_SHIFT); setMeasuredDimension(measuredWidth, shouldCollapse() ? 0 : measuredHeight); }
From source file:android.widget.Gallery.java
/** * Helper for makeAndAddView to set the position of a view and fill out its * layout parameters./*from ww w .j a va 2 s .c o m*/ * * @param child The view to position * @param offset Offset from the selected position * @param x X-coordinate indicating where this view should be placed. This * will either be the left or right edge of the view, depending on * the fromLeft parameter * @param fromLeft Are we positioning views based on the left edge? (i.e., * building from left to right)? */ private void setUpChild(View child, int offset, int x, boolean fromLeft) { // Respect layout params that are already in the view. Otherwise // make some up... Gallery.LayoutParams lp = (Gallery.LayoutParams) child.getLayoutParams(); if (lp == null) { lp = (Gallery.LayoutParams) generateDefaultLayoutParams(); } addViewInLayout(child, fromLeft != mIsRtl ? -1 : 0, lp); child.setSelected(offset == 0); // Get measure specs int childHeightSpec = ViewGroup.getChildMeasureSpec(mHeightMeasureSpec, mSpinnerPadding.top + mSpinnerPadding.bottom, lp.height); int childWidthSpec = ViewGroup.getChildMeasureSpec(mWidthMeasureSpec, mSpinnerPadding.left + mSpinnerPadding.right, lp.width); // Measure child child.measure(childWidthSpec, childHeightSpec); int childLeft; int childRight; // Position vertically based on gravity setting int childTop = calculateTop(child, true); int childBottom = childTop + child.getMeasuredHeight(); int width = child.getMeasuredWidth(); if (fromLeft) { childLeft = x; childRight = childLeft + width; } else { childLeft = x - width; childRight = x; } child.layout(childLeft, childTop, childRight, childBottom); }
From source file:com.example.newviewsplayground.WrappingSlidingPaneLayout.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { final int width = r - l; final int paddingLeft = getPaddingLeft(); final int paddingRight = getPaddingRight(); final int paddingTop = getPaddingTop(); final int childCount = getChildCount(); int xStart = paddingLeft; int nextXStart = xStart; if (mFirstLayout) { mSlideOffset = mCanSlide && mPreservedOpenState ? 1.f : 0.f; }// ww w . j ava 2 s . c o m for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); if (child.getVisibility() == GONE) { continue; } final LayoutParams lp = (LayoutParams) child.getLayoutParams(); final int childWidth = child.getMeasuredWidth(); int offset = 0; if (lp.slideable) { final int margin = lp.leftMargin + lp.rightMargin; final int range = Math.min(nextXStart, childWidth - paddingRight - mOverhangSize) - xStart - margin; mSlideRange = range; lp.dimWhenOffset = xStart + (width - childWidth) + lp.leftMargin + range + childWidth / 2 > width - paddingRight; xStart += (width - childWidth) + (int) (range * mSlideOffset) + lp.leftMargin; } else if (mCanSlide && mParallaxBy != 0) { offset = (int) ((1 - mSlideOffset) * mParallaxBy); xStart = nextXStart; } else { xStart = nextXStart; } final int childLeft = xStart - offset; final int childRight = childLeft + childWidth; final int childTop = paddingTop; final int childBottom = childTop + child.getMeasuredHeight(); child.layout(childLeft, paddingTop, childRight, childBottom); nextXStart += child.getWidth(); } if (mFirstLayout) { if (mCanSlide) { if (mParallaxBy != 0) { parallaxOtherViews(mSlideOffset); } if (((LayoutParams) mSlideableView.getLayoutParams()).dimWhenOffset) { dimChildView(mSlideableView, mSlideOffset, mSliderFadeColor); } } else { // Reset the dim level of all children; it's irrelevant when nothing moves. for (int i = 0; i < childCount; i++) { dimChildView(getChildAt(i), 0, mSliderFadeColor); } } updateObscuredViewsVisibility(mSlideableView); } mFirstLayout = false; }
From source file:com.android.leanlauncher.Workspace.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { Log.d(TAG, "OnLayout> " + getChildCount()); if (getChildCount() == 0) { return;/* w w w . j a v a 2 s .c om*/ } int offsetX = mWorkspace.getMeasuredWidth(); int offsetY = mWorkspace.getMeasuredHeight(); // Update the viewport offsets mViewPort.offset(offsetX, offsetY); final View child = getChildAt(0); if (child.getVisibility() != View.GONE) { child.layout(0, 0, child.getMeasuredWidth(), child.getMeasuredHeight()); } }
From source file:cn.emagsoftware.ui.BugFixedSlidingPaneLayout.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { final int width = r - l; final int paddingLeft = getPaddingLeft(); final int paddingRight = getPaddingRight(); final int paddingTop = getPaddingTop(); final int childCount = getChildCount(); int xStart = paddingLeft; int nextXStart = xStart; if (mFirstLayout) { mSlideOffset = mCanSlide && mPreservedOpenState ? 1.f : 0.f; }/* ww w . j av a 2 s .co m*/ for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); if (child.getVisibility() == GONE) { continue; } final LayoutParams lp = (LayoutParams) child.getLayoutParams(); final int childWidth = child.getMeasuredWidth(); int offset = 0; if (lp.slideable) { final int margin = lp.leftMargin + lp.rightMargin; final int range = Math.min(nextXStart, width - paddingRight - mOverhangSize) - xStart - margin; mSlideRange = range; lp.dimWhenOffset = xStart + lp.leftMargin + range + childWidth / 2 > width - paddingRight; xStart += (int) (range * mSlideOffset) + lp.leftMargin; } else if (mCanSlide && mParallaxBy != 0) { offset = (int) ((1 - mSlideOffset) * mParallaxBy); xStart = nextXStart; } else { xStart = nextXStart; } final int childLeft = xStart - offset; final int childRight = childLeft + childWidth; final int childTop = paddingTop; final int childBottom = childTop + child.getMeasuredHeight(); child.layout(childLeft, paddingTop, childRight, childBottom); nextXStart += child.getWidth(); } if (mFirstLayout) { if (mCanSlide) { if (mParallaxBy != 0) { parallaxOtherViews(mSlideOffset); } if (((LayoutParams) mSlideableView.getLayoutParams()).dimWhenOffset) { dimChildView(mSlideableView, mSlideOffset, mSliderFadeColor); } else { dimChildView(mSlideableView, 0, mSliderFadeColor); } } else { // Reset the dim level of all children; it's irrelevant when nothing moves. for (int i = 0; i < childCount; i++) { dimChildView(getChildAt(i), 0, mSliderFadeColor); } } updateObscuredViewsVisibility(mSlideableView); } mFirstLayout = false; }
From source file:com.cooper.redditvideo.CustomSlidingPaneLayout.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { final int width = r - l; final int paddingLeft = getPaddingLeft(); final int paddingRight = getPaddingRight(); final int paddingTop = getPaddingTop(); final int childCount = getChildCount(); int xStart = paddingLeft; int nextXStart = xStart; if (mFirstLayout) { mSlideOffset = mCanSlide && mPreservedOpenState ? 1.f : 0.f; }//from www . ja va2s . co m for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); if (child.getVisibility() == GONE) { continue; } final LayoutParams lp = (LayoutParams) child.getLayoutParams(); final int childWidth = child.getMeasuredWidth(); int offset = 0; if (lp.slideable) { final int margin = lp.leftMargin + lp.rightMargin; final int range = Math.min(nextXStart, width - paddingRight - mOverhangSize) - xStart - margin; mSlideRange = range; lp.dimWhenOffset = xStart + lp.leftMargin + range + childWidth / 2 > width - paddingRight; xStart += (int) (range * mSlideOffset) + lp.leftMargin; } else if (mCanSlide && mParallaxBy != 0) { offset = (int) ((1 - mSlideOffset) * mParallaxBy); xStart = nextXStart; } else { xStart = nextXStart; } final int childLeft = xStart - offset; final int childRight = childLeft + childWidth; final int childTop = paddingTop; final int childBottom = childTop + child.getMeasuredHeight(); child.layout(childLeft, paddingTop, childRight, childBottom); nextXStart += child.getWidth(); } if (mFirstLayout) { if (mCanSlide) { if (mParallaxBy != 0) { parallaxOtherViews(mSlideOffset); } if (((LayoutParams) mSlideableView.getLayoutParams()).dimWhenOffset) { dimChildView(mSlideableView, mSlideOffset, mSliderFadeColor); } } else { // Reset the dim level of all children; it's irrelevant when nothing moves. for (int i = 0; i < childCount; i++) { dimChildView(getChildAt(i), 0, mSliderFadeColor); } } updateObscuredViewsVisibility(mSlideableView); } mFirstLayout = false; }
From source file:com.abewy.android.apps.klyph.messenger.widget.SlidingPaneLayout.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { final int width = r - l; final int paddingLeft = getPaddingLeft(); final int paddingRight = getPaddingRight(); final int paddingTop = getPaddingTop(); final int childCount = getChildCount(); int xStart = paddingLeft; int nextXStart = xStart; if (mFirstLayout) { mSlideOffset = mCanSlide && mPreservedOpenState ? 1.f : 0.f; }/* w w w . j a v a 2s . c o m*/ for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); if (child.getVisibility() == GONE) { continue; } final LayoutParams lp = (LayoutParams) child.getLayoutParams(); final int childWidth = child.getMeasuredWidth(); int offset = 0; if (lp.slideable) { final int margin = lp.leftMargin + lp.rightMargin; final int range = Math.min(nextXStart, width - paddingRight - mOverhangSize) - xStart - margin; mSlideRange = range; lp.dimWhenOffset = true;//xStart + lp.leftMargin + range + childWidth / 2 > //width - paddingRight; xStart += (int) (range * mSlideOffset) + lp.leftMargin; } else if (mCanSlide && mParallaxBy != 0) { offset = (int) ((1 - mSlideOffset) * mParallaxBy); xStart = nextXStart; } else { xStart = nextXStart; } final int childLeft = xStart - offset; final int childRight = childLeft + childWidth; final int childTop = paddingTop; final int childBottom = childTop + child.getMeasuredHeight(); child.layout(childLeft, paddingTop, childRight, childBottom); nextXStart += child.getWidth(); } if (mFirstLayout) { if (mCanSlide) { if (mParallaxBy != 0) { parallaxOtherViews(mSlideOffset); } if (((LayoutParams) mSlideableView.getLayoutParams()).dimWhenOffset) { dimChildView(mSlideableView, mSlideOffset, mSliderFadeColor); } } else { // Reset the dim level of all children; it's irrelevant when nothing moves. for (int i = 0; i < childCount; i++) { dimChildView(getChildAt(i), 0, mSliderFadeColor); } } updateObscuredViewsVisibility(mSlideableView); } mFirstLayout = false; }
From source file:com.aviary.android.feather.sdk.widget.AviaryWorkspace.java
private void setUpChild(View child, int offset, int x, boolean fromLeft) { // Respect layout params that are already in the view. Otherwise // make some up... LayoutParams lp = child.getLayoutParams(); if (lp == null) { lp = (LayoutParams) generateDefaultLayoutParams(); }//from w w w. j a v a2 s . c o m addViewInLayout(child, fromLeft ? -1 : 0, lp); if (mAllowChildSelection) { // final boolean wantfocus = offset == 0; // child.setSelected( wantfocus ); // if( wantfocus ){ // child.requestFocus(); // } } // Get measure specs int childHeightSpec = ViewGroup.getChildMeasureSpec(mHeightMeasureSpec, mPaddingTop + mPaddingBottom, lp.height); int childWidthSpec = ViewGroup.getChildMeasureSpec(mWidthMeasureSpec, mPaddingLeft + mPaddingRight, lp.width); // Measure child child.measure(childWidthSpec, childHeightSpec); int childLeft; int childRight; // Position vertically based on gravity setting int childTop = calculateTop(child, true); int childBottom = childTop + child.getMeasuredHeight(); int width = child.getMeasuredWidth(); if (fromLeft) { childLeft = x; childRight = childLeft + width; } else { childLeft = x - width; childRight = x; } child.layout(childLeft, childTop, childRight, childBottom); }