List of usage examples for android.view View getMeasuredWidth
public final int getMeasuredWidth()
From source file:aksha.upcomingdemo.HorizontalListView.java
private void fillListLeft(int leftEdge, final int dx) { // Loop adding views to the left until the screen is filled while (leftEdge + dx - mDividerWidth > 0 && mLeftViewAdapterIndex >= 1) { mLeftViewAdapterIndex--;//from w w w. ja v a 2 s . c o m View child = mAdapter.getView(mLeftViewAdapterIndex, getRecycledView(mLeftViewAdapterIndex), this); addAndMeasureChild(child, INSERT_AT_START_OF_LIST); // If first view, then no divider to the left of it leftEdge -= mLeftViewAdapterIndex == 0 ? child.getMeasuredWidth() : mDividerWidth + child.getMeasuredWidth(); // If on a clean edge then just remove the child, otherwise remove the divider as well mDisplayOffset -= leftEdge + dx == 0 ? child.getMeasuredWidth() : mDividerWidth + child.getMeasuredWidth(); } }
From source file:com.dm.xz.views.PinnedSectionListView.java
/** Create shadow wrapper with a pinned view for a view at given position */ void createPinnedShadow(int position) { // try to recycle shadow PinnedSection pinnedShadow = mRecycleSection; mRecycleSection = null;/*from w ww . ja v a 2s . c o m*/ // create new shadow, if needed if (pinnedShadow == null) pinnedShadow = new PinnedSection(); // request new view using recycled view, if such View pinnedView = getAdapter().getView(position, pinnedShadow.view, PinnedSectionListView.this); // read layout parameters LayoutParams layoutParams = (LayoutParams) pinnedView.getLayoutParams(); if (layoutParams == null) { layoutParams = (LayoutParams) generateDefaultLayoutParams(); pinnedView.setLayoutParams(layoutParams); } int heightMode = MeasureSpec.getMode(layoutParams.height); int heightSize = MeasureSpec.getSize(layoutParams.height); if (heightMode == MeasureSpec.UNSPECIFIED) heightMode = MeasureSpec.EXACTLY; int maxHeight = getHeight() - getListPaddingTop() - getListPaddingBottom(); if (heightSize > maxHeight) heightSize = maxHeight; // measure & layout int ws = MeasureSpec.makeMeasureSpec(getWidth() - getListPaddingLeft() - getListPaddingRight(), MeasureSpec.EXACTLY); int hs = MeasureSpec.makeMeasureSpec(heightSize, heightMode); pinnedView.measure(ws, hs); pinnedView.layout(0, 0, pinnedView.getMeasuredWidth(), pinnedView.getMeasuredHeight()); mTranslateY = 0; // initialize pinned shadow pinnedShadow.view = pinnedView; pinnedShadow.position = position; pinnedShadow.id = getAdapter().getItemId(position); // store pinned shadow mPinnedSection = pinnedShadow; }
From source file:com.ftinc.kit.attributr.ui.widget.StickyRecyclerHeadersElevationDecoration.java
/** * Gets the header view for the associated position. If it doesn't exist yet, it will be * created, measured, and laid out.//from www. j a v a 2s.c om * @param parent * @param position * @return Header view */ public View getHeaderView(RecyclerView parent, int position) { long headerId = mAdapter.getHeaderId(position); RecyclerView.ViewHolder viewHolder = mHeaderViews.get(headerId); if (viewHolder == null) { viewHolder = mAdapter.onCreateHeaderViewHolder(parent); View header = viewHolder.itemView; header.setTag(viewHolder); if (header.getLayoutParams() == null) { header.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); } int widthSpec; int heightSpec; if (getOrientation(parent) == LinearLayoutManager.VERTICAL) { widthSpec = View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.EXACTLY); heightSpec = View.MeasureSpec.makeMeasureSpec(parent.getHeight(), View.MeasureSpec.UNSPECIFIED); } else { widthSpec = View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.UNSPECIFIED); heightSpec = View.MeasureSpec.makeMeasureSpec(parent.getHeight(), View.MeasureSpec.EXACTLY); } 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()); mHeaderViews.put(headerId, viewHolder); } // Rebind content to the view holder mAdapter.onBindHeaderViewHolder(viewHolder, position); return viewHolder.itemView; }
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; }// w w w.ja va 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:aksha.upcomingdemo.HorizontalListView.java
private void fillListRight(int rightEdge, final int dx) { // Loop adding views to the right until the screen is filled while (rightEdge + dx + mDividerWidth < getWidth() && mRightViewAdapterIndex + 1 < mAdapter.getCount()) { mRightViewAdapterIndex++;//w ww .j a v a 2 s .c o m // If mLeftViewAdapterIndex < 0 then this is the first time a view is being added, and left == right if (mLeftViewAdapterIndex < 0) { mLeftViewAdapterIndex = mRightViewAdapterIndex; } // Get the view from the adapter, utilizing a cached view if one is available View child = mAdapter.getView(mRightViewAdapterIndex, getRecycledView(mRightViewAdapterIndex), this); addAndMeasureChild(child, INSERT_AT_END_OF_LIST); // If first view, then no divider to the left of it, otherwise add the space for the divider width rightEdge += (mRightViewAdapterIndex == 0 ? 0 : mDividerWidth) + child.getMeasuredWidth(); // Check if we are running low on data so we can tell listeners to go get more determineIfLowOnData(); } }
From source file:com.apptentive.android.sdk.module.messagecenter.view.MessageCenterListView.java
/** * Create shadow wrapper with a sticky view at given position *//*w ww. j a v a 2 s.c om*/ void createStickyShadow(int position) { // recycle shadow StickyWrapper stickyViewShadow = recycledHeaderView; recycledHeaderView = null; // create new shadow, if needed if (stickyViewShadow == null) { stickyViewShadow = new StickyWrapper(); } // request new view using recycled view, if such View stickyView = getAdapter().getView(position, stickyViewShadow.view, MessageCenterListView.this); // read layout parameters LayoutParams layoutParams = (LayoutParams) stickyView.getLayoutParams(); if (layoutParams == null) { layoutParams = (LayoutParams) generateDefaultLayoutParams(); stickyView.setLayoutParams(layoutParams); } View childLayout = ((ViewGroup) stickyView).getChildAt(0); int heightMode = MeasureSpec.getMode(layoutParams.height); int heightSize = MeasureSpec.getSize(layoutParams.height); if (heightMode == MeasureSpec.UNSPECIFIED) { heightMode = MeasureSpec.EXACTLY; } int maxHeight = getHeight() - getListPaddingTop() - getListPaddingBottom(); if (heightSize > maxHeight) { heightSize = maxHeight; } // assuming left and right additional paddings are the same int ws = MeasureSpec.makeMeasureSpec(getWidth() - getListPaddingLeft() - getListPaddingRight(), MeasureSpec.EXACTLY); int hs = MeasureSpec.makeMeasureSpec(heightSize, heightMode); stickyView.measure(ws, hs); stickyView.layout(0, 0, stickyView.getMeasuredWidth(), stickyView.getMeasuredHeight()); // initialize shadow stickyViewShadow.view = stickyView; stickyViewShadow.position = position; stickyViewShadow.id = getAdapter().getItemId(position); stickyViewShadow.additionalIndent = childLayout.getPaddingLeft(); stickyWrapper = stickyViewShadow; }
From source file:com.github.shareme.gwsstickyheadersrv.library.caching.HeaderViewCache.java
@SuppressWarnings("unchecked") @Override//from w w w .j a va 2 s. c o m public View getHeader(RecyclerView parent, int position) { long headerId = mAdapter.getHeaderId(position); View header = mHeaderViews.get(headerId); if (header == null) { //TODO - recycle views RecyclerView.ViewHolder viewHolder = mAdapter.onCreateHeaderViewHolder(parent); mAdapter.onBindHeaderViewHolder(viewHolder, position); header = viewHolder.itemView; if (header.getLayoutParams() == null) { header.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); } int widthSpec; int heightSpec; if (mOrientationProvider.getOrientation(parent) == LinearLayoutManager.VERTICAL) { widthSpec = View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.EXACTLY); heightSpec = View.MeasureSpec.makeMeasureSpec(parent.getHeight(), View.MeasureSpec.UNSPECIFIED); } else { widthSpec = View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.UNSPECIFIED); heightSpec = View.MeasureSpec.makeMeasureSpec(parent.getHeight(), View.MeasureSpec.EXACTLY); } 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()); mHeaderViews.put(headerId, header); } return header; }
From source file:com.gather.android.widget.HorizontalListView.java
private void fillListRight(int rightEdge, final int dx) { // Loop adding views to the right until the screen is filled while (rightEdge + dx + mDividerWidth < getWidth() && mRightViewAdapterIndex + 1 < mAdapter.getCount()) { mRightViewAdapterIndex++;// w w w .j a v a 2 s . c o m // If mLeftViewAdapterIndex < 0 then this is the first time a view is being added, and left == right if (mLeftViewAdapterIndex < 0) { mLeftViewAdapterIndex = mRightViewAdapterIndex; } // Get the view from the adapter, utilizing a cached view if one is available View child = mAdapter.getView(mRightViewAdapterIndex, getRecycledView(mRightViewAdapterIndex), this); addAndMeasureChild(child, INSERT_AT_END_OF_LIST); // If first view, then no divider to the left of it, otherwise add the space for the divider width rightEdge += (mRightViewAdapterIndex == 0 ? 0 : mDividerWidth) + child.getMeasuredWidth(); // Check if we are running low on data so we can tell listeners to go get more determineIfLowOnData(); } if (scrollingListener != null) { scrollingListener.onScroll(mRightViewAdapterIndex, mRightViewAdapterIndex); } }
From source file:com.grottworkshop.gwsswipelayout.SwipeLayout.java
protected Rect getRelativePosition(View child) { View t = child;/*ww w . j a v a 2 s . co m*/ Rect r = new Rect(t.getLeft(), t.getTop(), 0, 0); while (t.getParent() != null && t != getRootView()) { t = (View) t.getParent(); if (t == this) break; r.left += t.getLeft(); r.top += t.getTop(); } r.right = r.left + child.getMeasuredWidth(); r.bottom = r.top + child.getMeasuredHeight(); return r; }
From source file:cn.com.zzwfang.view.directionalviewpager.DirectionalViewPager.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { mInLayout = true;/*from www .j a v a 2s .c o m*/ populate(); mInLayout = false; final int count = getChildCount(); final int size = (mOrientation == HORIZONTAL) ? r - l : b - t; for (int i = 0; i < count; i++) { View child = getChildAt(i); ItemInfo ii; if (child.getVisibility() != GONE && (ii = infoForChild(child)) != null) { int off = size * ii.position; int childLeft = getPaddingLeft(); int childTop = getPaddingTop(); if (mOrientation == HORIZONTAL) { childLeft += off; } else { childTop += off; } 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()); } } }