List of usage examples for android.view View getMeasuredWidth
public final int getMeasuredWidth()
From source file:ca.barrenechea.widget.recyclerview.decoration.StickyHeaderDecoration.java
private RecyclerView.ViewHolder getHeader(RecyclerView parent, int position) { final long key = mAdapter.getHeaderId(position); if (mHeaderCache.containsKey(key)) { return mHeaderCache.get(key); } else {/*from w ww . ja v a 2 s .co m*/ final RecyclerView.ViewHolder holder = mAdapter.onCreateHeaderViewHolder(parent); final View header = holder.itemView; //noinspection unchecked mAdapter.onBindHeaderViewHolder(holder, position); int widthSpec = View.MeasureSpec.makeMeasureSpec(parent.getMeasuredWidth(), View.MeasureSpec.EXACTLY); int heightSpec = View.MeasureSpec.makeMeasureSpec(parent.getMeasuredHeight(), View.MeasureSpec.UNSPECIFIED); int childWidth = ViewGroup.getChildMeasureSpec(widthSpec, parent.getPaddingLeft() + parent.getPaddingRight(), header.getLayoutParams().width); int childHeight = ViewGroup.getChildMeasureSpec(heightSpec, parent.getPaddingTop() + parent.getPaddingBottom(), header.getLayoutParams().height); header.measure(childWidth, childHeight); header.layout(0, 0, header.getMeasuredWidth(), header.getMeasuredHeight()); mHeaderCache.put(key, holder); return holder; } }
From source file:com.coco.slidinguppanel.SlidingUpPanel.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (getChildCount() > 1) { throw new IllegalStateException("SlidingUpPanel can only contain on child view"); } else {//from w ww . j a v a 2 s . c om int maxWidth = 0; int maxHeight = 0; if (getChildCount() == 1) { final View child = getChildAt(0); if (child.getVisibility() != GONE) { measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0); final MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams(); maxWidth = child.getMeasuredWidth() + getPaddingLeft() + getPaddingRight() + lp.leftMargin + lp.rightMargin; maxHeight = child.getMeasuredHeight() + getPaddingTop() + getPaddingBottom() + lp.topMargin + lp.bottomMargin; } } // Check against our minimum height and width maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth()); maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight()); // Report our final dimensions. setMeasuredDimension(resolveSize(maxWidth, widthMeasureSpec), resolveSize(maxHeight, heightMeasureSpec)); } }
From source file:com.example.youngkaaa.youngseedemo1.utils.recyclerUtils.BaseItemAnimator.java
public void clear(View v) { ViewCompat.setAlpha(v, 1);/*from www. j av a 2s . c o m*/ ViewCompat.setScaleY(v, 1); ViewCompat.setScaleX(v, 1); ViewCompat.setTranslationY(v, 0); ViewCompat.setTranslationX(v, 0); ViewCompat.setRotation(v, 0); ViewCompat.setRotationY(v, 0); ViewCompat.setRotationX(v, 0); ViewCompat.setPivotY(v, v.getMeasuredHeight() / 2); ViewCompat.setPivotX(v, v.getMeasuredWidth() / 2); ViewCompat.animate(v).setInterpolator(null).setStartDelay(0); }
From source file:com.aretha.slidemenu.SlideMenu.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { final int count = getChildCount(); final int paddingLeft = getPaddingLeft(); final int paddingRight = getPaddingRight(); final int paddingTop = getPaddingTop(); final int statusBarHeight = mSlideMode == MODE_SLIDE_WINDOW ? STATUS_BAR_HEIGHT : 0; for (int index = 0; index < count; index++) { View child = getChildAt(index); final int measureWidth = child.getMeasuredWidth(); final int measureHeight = child.getMeasuredHeight(); LayoutParams layoutParams = (LayoutParams) child.getLayoutParams(); switch (layoutParams.role) { case LayoutParams.ROLE_CONTENT: // we should display the content in front of all other views child.bringToFront();/*from ww w .java 2 s . com*/ child.layout(mCurrentContentOffset + paddingLeft, paddingTop, paddingLeft + measureWidth + mCurrentContentOffset, paddingTop + measureHeight); break; case LayoutParams.ROLE_PRIMARY_MENU: mContentBoundsRight = measureWidth; child.layout(paddingLeft, statusBarHeight + paddingTop, paddingLeft + measureWidth, statusBarHeight + paddingTop + measureHeight); break; case LayoutParams.ROLE_SECONDARY_MENU: mContentBoundsLeft = -measureWidth; child.layout(r - paddingRight - measureWidth, statusBarHeight + paddingTop, r - paddingRight, statusBarHeight + t + measureHeight); break; default: continue; } } }
From source file:be.virtualsushi.gaz.view.ActivityChooserView.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { View child = mActivityChooserContent; // If the default action is not visible we want to be as tall as the // ActionBar so if this widget is used in the latter it will look as // a normal action button. heightMeasureSpec = MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(heightMeasureSpec), MeasureSpec.EXACTLY);//from ww w.j ava 2 s.c o m measureChild(child, widthMeasureSpec, heightMeasureSpec); setMeasuredDimension(child.getMeasuredWidth(), child.getMeasuredHeight()); }
From source file:com.bigpigs.fragments.SearchFragment.java
private Bitmap getMarkerBitmapFromView(@DrawableRes int resId) { View customMarkerView = ((LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE)) .inflate(R.layout.custom_marker, null); ImageView markerImageView = (ImageView) customMarkerView.findViewById(R.id.marker_icon); markerImageView.setImageResource(resId); customMarkerView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); customMarkerView.layout(0, 0, customMarkerView.getMeasuredWidth(), customMarkerView.getMeasuredHeight()); customMarkerView.buildDrawingCache(); Bitmap returnedBitmap = Bitmap.createBitmap(customMarkerView.getMeasuredWidth(), customMarkerView.getMeasuredHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(returnedBitmap); canvas.drawColor(Color.WHITE, PorterDuff.Mode.SRC_IN); Drawable drawable = customMarkerView.getBackground(); if (drawable != null) drawable.draw(canvas);/*ww w.ja va2 s .c o m*/ customMarkerView.draw(canvas); return returnedBitmap; }
From source file:com.example.guxiuzhong.pagerslidingtab_lib.PagerSlidingTabStrip.java
protected void animateFadeScale(View left, View right, float positionOffset, int position) { if (mState != State.IDLE) { if (left != null) { ViewHelper.setAlpha(tabViews.get(position).get("normal"), positionOffset); ViewHelper.setAlpha(tabViews.get(position).get("selected"), 1 - positionOffset); float mScale = 1 + zoomMax - zoomMax * positionOffset; ViewHelper.setPivotX(left, left.getMeasuredWidth() * 0.5f); ViewHelper.setPivotY(left, left.getMeasuredHeight() * 0.5f); ViewHelper.setScaleX(left, mScale); ViewHelper.setScaleY(left, mScale); }/*ww w . ja va2 s . c o m*/ if (right != null) { ViewHelper.setAlpha(tabViews.get(position + 1).get("normal"), 1 - positionOffset); ViewHelper.setAlpha(tabViews.get(position + 1).get("selected"), positionOffset); float mScale = 1 + zoomMax * positionOffset; ViewHelper.setPivotX(right, right.getMeasuredWidth() * 0.5f); ViewHelper.setPivotY(right, right.getMeasuredHeight() * 0.5f); ViewHelper.setScaleX(right, mScale); ViewHelper.setScaleY(right, mScale); } } }
From source file:com.android.launcher3.folder.FolderIcon.java
public Drawable prepareCreate(final View destView) { Drawable animateDrawable = getTopDrawable((TextView) destView); computePreviewDrawingParams(animateDrawable.getIntrinsicWidth(), destView.getMeasuredWidth()); return animateDrawable; }
From source file:com.facebook.litho.MountState.java
private static void applyBoundsToMountContent(Object content, int left, int top, int right, int bottom, boolean force) { assertMainThread();//from www .j ava 2 s .c o m if (content instanceof View) { View view = (View) content; int width = right - left; int height = bottom - top; if (force || view.getMeasuredHeight() != height || view.getMeasuredWidth() != width) { view.measure(makeMeasureSpec(right - left, MeasureSpec.EXACTLY), makeMeasureSpec(bottom - top, MeasureSpec.EXACTLY)); } if (force || view.getLeft() != left || view.getTop() != top || view.getRight() != right || view.getBottom() != bottom) { view.layout(left, top, right, bottom); } } else if (content instanceof Drawable) { ((Drawable) content).setBounds(left, top, right, bottom); } else { throw new IllegalStateException("Unsupported mounted content " + content); } }
From source file:android.support.v7.internal.widget.SpinnerCompat.java
/** * Creates and positions all views for this Spinner. * * @param delta Change in the selected position. +1 means selection is moving to the right, so * views are scrolling to the left. -1 means selection is moving to the left. *///from w ww. j a v a 2s . c om @Override void layout(int delta, boolean animate) { int childrenLeft = mSpinnerPadding.left; int childrenWidth = getRight() - getLeft() - mSpinnerPadding.left - mSpinnerPadding.right; if (mDataChanged) { handleDataChanged(); } // Handle the empty set by removing all views if (mItemCount == 0) { resetList(); return; } if (mNextSelectedPosition >= 0) { setSelectedPositionInt(mNextSelectedPosition); } recycleAllViews(); // Clear out old views removeAllViewsInLayout(); // Make selected view and position it mFirstPosition = mSelectedPosition; if (mAdapter != null) { View sel = makeView(mSelectedPosition, true); int width = sel.getMeasuredWidth(); int selectedOffset = childrenLeft; final int layoutDirection = ViewCompat.getLayoutDirection(this); final int absoluteGravity = GravityCompat.getAbsoluteGravity(mGravity, layoutDirection); switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: selectedOffset = childrenLeft + (childrenWidth / 2) - (width / 2); break; case Gravity.RIGHT: selectedOffset = childrenLeft + childrenWidth - width; break; } sel.offsetLeftAndRight(selectedOffset); } // Flush any cached views that did not get reused above mRecycler.clear(); invalidate(); checkSelectionChanged(); mDataChanged = false; mNeedSync = false; setNextSelectedPositionInt(mSelectedPosition); }