List of usage examples for android.view View getMeasuredWidth
public final int getMeasuredWidth()
From source file:com.actionbarsherlock.custom.widget.VerticalDrawerLayout.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { mInLayout = true;// w w w . j a v a 2s . c o m 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 { // Drawer, if it wasn't onMeasure would have thrown an exception. final int childWidth = child.getMeasuredWidth(); final int childHeight = child.getMeasuredHeight(); int childTop; if (checkDrawerViewGravity(child, Gravity.TOP)) { childTop = -childHeight + (int) (childHeight * lp.onScreen); } else { // Bottom; onMeasure checked for us. childTop = b - t - (int) (childHeight * lp.onScreen); } final int vgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK; switch (vgrav) { default: case Gravity.LEFT: { child.layout(lp.leftMargin, childTop, childWidth, childTop + childHeight); break; } case Gravity.RIGHT: { final int width = r - l; child.layout(width - lp.rightMargin - child.getMeasuredWidth(), childTop, width - lp.rightMargin, childTop + childHeight); break; } case Gravity.CENTER_HORIZONTAL: { final int width = r - l; int childLeft = (width - childWidth) / 2; // Offset for margins. If things don't fit right because of // bad measurement before, oh well. if (childLeft < lp.leftMargin) { childLeft = lp.leftMargin; } else if (childLeft + childWidth > width - lp.rightMargin) { childLeft = width - lp.rightMargin - childWidth; } child.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight); break; } } if (lp.onScreen == 0) { child.setVisibility(INVISIBLE); } } } mInLayout = false; mFirstLayout = false; }
From source file:com.aidy.bottomdrawerlayout.BottomDrawerLayout.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { Log.i(TAG, "onLayout()"); mInLayout = true;//from w w w . j av a 2 s . c o m 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 { final int childWidth = child.getMeasuredWidth(); final int childHeight = child.getMeasuredHeight(); int childTop; final float newOffset; if (checkDrawerViewAbsoluteGravity(child, Gravity.BOTTOM)) { childTop = height - (int) (childHeight * lp.onScreen); newOffset = (float) (height - childTop) / childWidth; } else { childTop = -childHeight + (int) (childHeight * lp.onScreen); newOffset = (float) (childHeight + childTop) / childHeight; } final boolean changeOffset = newOffset != lp.onScreen; final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK; switch (vgrav) { default: case Gravity.LEFT: { child.layout(lp.leftMargin, childTop, lp.leftMargin + childWidth, childTop + childHeight); break; } case Gravity.RIGHT: { child.layout(width - lp.rightMargin, childTop, width - lp.rightMargin, childTop + childHeight); break; } case Gravity.CENTER_HORIZONTAL: { int childLeft = (width - childWidth) / 2; if (childLeft < lp.leftMargin) { childLeft = lp.leftMargin; } else if (childLeft + childWidth > width - lp.rightMargin) { childLeft = width - lp.rightMargin - childWidth; } child.layout(childLeft, childTop, childLeft + childWidth, childTop + 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:android.widget.Gallery.java
/** * Obtain a view, either by pulling an existing view from the recycler or by * getting a new one from the adapter. If we are animating, make sure there * is enough information in the view's layout parameters to animate from the * old to new positions.// w w w . java 2 s. co m * * @param position Position in the gallery for the view to obtain * @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)? * @return A view that has been added to the gallery */ private View makeAndAddView(int position, int offset, int x, boolean fromLeft) { View child; if (!mDataChanged) { child = mRecycler.get(position); if (child != null) { // Can reuse an existing view int childLeft = child.getLeft(); // Remember left and right edges of where views have been placed mRightMost = Math.max(mRightMost, childLeft + child.getMeasuredWidth()); mLeftMost = Math.min(mLeftMost, childLeft); // Position the view setUpChild(child, offset, x, fromLeft); return child; } } // Nothing found in the recycler -- ask the adapter for a view child = mAdapter.getView(position, null, this); // Position the view setUpChild(child, offset, x, fromLeft); return child; }
From source file:cc.echonet.coolmicapp.MainActivity.java
private void goAbout() { Log.d("MainActivity", "goAbout() "); LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View popUpView = inflater.inflate(R.layout.popup_about, null, false); final PopupWindow popUp = new PopupWindow(this); Button close = (Button) popUpView.findViewById(R.id.cmdPopUpDismiss); close.setOnClickListener(new View.OnClickListener() { public void onClick(View popupView) { popUp.dismiss();//from w w w . ja v a2s. c o m } }); ((TextView) popUpView.findViewById(R.id.txtVersion)).setText(BuildConfig.VERSION_NAME); ((TextView) popUpView.findViewById(R.id.txtBuildType)).setText(BuildConfig.BUILD_TYPE); ((TextView) popUpView.findViewById(R.id.txtGITBranch)).setText(BuildConfig.GIT_BRANCH); ((TextView) popUpView.findViewById(R.id.txtGITRevision)).setText(BuildConfig.GIT_REVISION); ((TextView) popUpView.findViewById(R.id.txtGITAuthor)).setText(BuildConfig.GIT_AUTHOR); ((TextView) popUpView.findViewById(R.id.txtGITDirty)).setText(BuildConfig.GIT_DIRTY); popUpView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); popUp.setContentView(popUpView); Log.d("MainActivity", String.format("h: %s w: %s h: %s w: %s", popUp.getHeight(), popUp.getWidth(), popUpView.getMeasuredHeight(), popUpView.getMeasuredWidth())); popUp.setHeight(popUpView.getMeasuredHeight()); popUp.setWidth(popUpView.getMeasuredWidth()); popUp.showAtLocation(popUpView, Gravity.CENTER, 0, 0); Log.d("MainActivity", "goAbout() end "); }
From source file:com.ecom.consumer.customviews.HorizontalListView.java
/** Loops through each child and positions them onto the screen */ private void positionChildren(final int dx) { int childCount = getChildCount(); if (childCount > 0) { mDisplayOffset += dx;//from ww w .j ava 2 s . co m int leftOffset = mDisplayOffset + mDividerWidth; // Loop each child view for (int i = 0; i < childCount; i++) { View child = getChildAt(i); int left = leftOffset + getPaddingLeft(); int top = getPaddingTop(); int right = left + child.getMeasuredWidth(); int bottom = top + child.getMeasuredHeight(); // Layout the child child.layout(left, top, right, bottom); // Increment our offset by added child's size and divider width leftOffset += child.getMeasuredWidth() + mDividerWidth; } } }
From source file:com.abewy.android.apps.klyph.widget.KlyphDrawerLayout.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { mInLayout = true;/*from w w w . j a v a2 s .c o m*/ final int width = r - l; 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 { // Drawer, if it wasn't onMeasure would have thrown an exception. final int childWidth = child.getMeasuredWidth(); final int childHeight = child.getMeasuredHeight(); int childLeft; final float newOffset; if (checkDrawerViewGravity(child, Gravity.LEFT)) { childLeft = -childWidth + (int) (childWidth * lp.onScreen); newOffset = (float) (childWidth + childLeft) / childWidth; } else { // Right; onMeasure checked for us. childLeft = width - (int) (childWidth * lp.onScreen); newOffset = (float) (width - childLeft) / childWidth; } final boolean changeOffset = newOffset != lp.onScreen; final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK; switch (vgrav) { default: case Gravity.TOP: { child.layout(childLeft, lp.topMargin, childLeft + childWidth, childHeight); break; } case Gravity.BOTTOM: { final int height = b - t; child.layout(childLeft, height - lp.bottomMargin - child.getMeasuredHeight(), childLeft + childWidth, height - lp.bottomMargin); break; } case Gravity.CENTER_VERTICAL: { final int height = b - t; int childTop = (height - childHeight) / 2; // Offset for margins. If things don't fit right because of // bad measurement before, oh well. if (childTop < lp.topMargin) { childTop = lp.topMargin; } else if (childTop + childHeight > height - lp.bottomMargin) { childTop = height - lp.bottomMargin - childHeight; } child.layout(childLeft, childTop, childLeft + childWidth, childTop + 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:aksha.upcomingdemo.HorizontalListView.java
private void removeNonVisibleChildren(final int dx) { View child = getLeftmostChild(); // Loop removing the leftmost child, until that child is on the screen while (child != null && child.getRight() + dx <= 0) { // The child is being completely removed so remove its width from the display offset and its divider if it has one. // To remove add the size of the child and its divider (if it has one) to the offset. // You need to add since its being removed from the left side, i.e. shifting the offset to the right. mDisplayOffset += isLastItemInAdapter(mLeftViewAdapterIndex) ? child.getMeasuredWidth() : mDividerWidth + child.getMeasuredWidth(); // Add the removed view to the cache recycleView(mLeftViewAdapterIndex, child); // Actually remove the view removeViewInLayout(child);//from w ww .jav a2 s . c o m // Keep track of the adapter index of the left most child mLeftViewAdapterIndex++; // Get the new leftmost child child = getLeftmostChild(); } child = getRightmostChild(); // Loop removing the rightmost child, until that child is on the screen while (child != null && child.getLeft() + dx >= getWidth()) { recycleView(mRightViewAdapterIndex, child); removeViewInLayout(child); mRightViewAdapterIndex--; child = getRightmostChild(); } }
From source file:com.daiv.android.twitter.manipulations.widgets.NotificationDrawerLayout.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { mInLayout = true;/*from w w w. j a v a 2s .co m*/ final int width = r - l; 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)) { try { child.layout(lp.leftMargin, lp.topMargin, lp.leftMargin + child.getMeasuredWidth(), lp.topMargin + child.getMeasuredHeight()); } catch (Exception e) { } } else { // Drawer, if it wasn't onMeasure would have thrown an exception. final int childWidth = child.getMeasuredWidth(); final int childHeight = child.getMeasuredHeight(); int childLeft; final float newOffset; if (checkDrawerViewGravity(child, Gravity.LEFT)) { childLeft = -childWidth + (int) (childWidth * lp.onScreen); newOffset = (float) (childWidth + childLeft) / childWidth; } else { // Right; onMeasure checked for us. childLeft = width - (int) (childWidth * lp.onScreen); newOffset = (float) (width - childLeft) / childWidth; } final boolean changeOffset = newOffset != lp.onScreen; final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK; switch (vgrav) { default: case Gravity.TOP: { child.layout(childLeft, lp.topMargin, childLeft + childWidth, childHeight); break; } case Gravity.BOTTOM: { final int height = b - t; child.layout(childLeft, height - lp.bottomMargin - child.getMeasuredHeight(), childLeft + childWidth, height - lp.bottomMargin); break; } case Gravity.CENTER_VERTICAL: { final int height = b - t; int childTop = (height - childHeight) / 2; // Offset for margins. If things don't fit right because of // bad measurement before, oh well. if (childTop < lp.topMargin) { childTop = lp.topMargin; } else if (childTop + childHeight > height - lp.bottomMargin) { childTop = height - lp.bottomMargin - childHeight; } child.layout(childLeft, childTop, childLeft + childWidth, childTop + 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:com.actionbarsherlock.internal.widget.IcsSpinner.java
/** * Helper for makeAndAddView to set the position of a view * and fill out its layout paramters.//from ww w. j a v a2 s. com * * @param child The view to position */ private void setUpChild(View child) { // Respect layout params that are already in the view. Otherwise // make some up... ViewGroup.LayoutParams lp = child.getLayoutParams(); if (lp == null) { lp = generateDefaultLayoutParams(); } addViewInLayout(child, 0, lp); child.setSelected(hasFocus()); if (mDisableChildrenWhenDisabled) { child.setEnabled(isEnabled()); } // 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 = mSpinnerPadding.top + ((getMeasuredHeight() - mSpinnerPadding.bottom - mSpinnerPadding.top - child.getMeasuredHeight()) / 2); int childBottom = childTop + child.getMeasuredHeight(); int width = child.getMeasuredWidth(); childLeft = 0; childRight = childLeft + width; child.layout(childLeft, childTop, childRight, childBottom); }
From source file:cn.zmdx.kaka.locker.widget.SlidingPaneLayout.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { final boolean isLayoutRtl = isLayoutRtlSupport(); if (isLayoutRtl) { mDragHelper.setEdgeTrackingEnabled(ViewDragHelper.EDGE_RIGHT); } else {//from w w w . j a v a2 s . com mDragHelper.setEdgeTrackingEnabled(ViewDragHelper.EDGE_LEFT); } final int width = r - l; final int paddingStart = isLayoutRtl ? getPaddingRight() : getPaddingLeft(); final int paddingEnd = isLayoutRtl ? getPaddingLeft() : getPaddingRight(); final int paddingTop = getPaddingTop(); final int childCount = getChildCount(); int xStart = paddingStart; int nextXStart = xStart; if (mFirstLayout) { mSlideOffset = mCanSlide && mPreservedOpenState ? 1.f : 0.f; } 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 = isLayoutRtl ? lp.rightMargin : 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; if (isLayoutRtl) { childRight = width - xStart + offset; childLeft = childRight - childWidth; } else { childLeft = xStart - offset; 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; }