List of usage examples for android.view ViewGroup getChildMeasureSpec
public static int getChildMeasureSpec(int spec, int padding, int childDimension)
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 w w. jav a 2s.c o 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:cn.lanmei.com.dingdong_2.ItemDecoration.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 {/* w w w .ja va 2s.com*/ final RecyclerView.ViewHolder holder = mAdapter.onCreateHeaderViewHolder(parent); final View header = holder.itemView; //noinspection unchecked mAdapter.onBindHeaderViewHolder(holder, position); int widthSpec = View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.EXACTLY); int heightSpec = View.MeasureSpec.makeMeasureSpec(parent.getHeight(), 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:ca.barrenechea.widget.recyclerview.decoration.DoubleHeaderDecoration.java
private void measureView(RecyclerView parent, View header) { int widthSpec = View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.EXACTLY); int heightSpec = View.MeasureSpec.makeMeasureSpec(parent.getHeight(), 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()); }
From source file:com.charon.materialsample.view.ScrollingTabs.java
public static void measureView(View view) { ViewGroup.LayoutParams lp = view.getLayoutParams(); if (lp == null) { lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); }/*from w w w. java 2 s . c o m*/ int childMeasureWidth = ViewGroup.getChildMeasureSpec(0, 0, lp.width); int childMeasureHeight; if (lp.height > 0) { childMeasureHeight = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY); } else { // Measure specification mode: The parent has not imposed any // constraint on the child. It can be whatever size it wants. childMeasureHeight = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); } view.measure(childMeasureWidth, childMeasureHeight); }
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 w w w .ja va2 s . 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.library.core.view.HorizontalListView.java
private void addAndMeasureChild(final View child, int viewPos) { LayoutParams params = (LayoutParams) child.getLayoutParams(); params = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT); addViewInLayout(child, viewPos, params, true); int heightMeasureSpec = MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.EXACTLY); int childHeightSpec = ViewGroup.getChildMeasureSpec(heightMeasureSpec, getPaddingTop() + getPaddingBottom(), params.height);//from ww w. jav a 2 s . c o m int childWidthSpec = MeasureSpec.makeMeasureSpec(params.width > 0 ? params.width : 0, MeasureSpec.UNSPECIFIED); child.measure(childWidthSpec, childHeightSpec); }
From source file:com.android.yijiang.kzx.widget.tab.PagerSlidingTabStrip.java
/** * ????ViewgetMeasuredXXX()????/*from w w w. j a v a 2s. c o m*/ */ private View measure(View view) { ViewGroup.LayoutParams p = view.getLayoutParams(); if (p == null) { p = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); } int childWidthSpec = ViewGroup.getChildMeasureSpec(0, 0, p.width); int lpHeight = p.height; int childHeightSpec; if (lpHeight > 0) { childHeightSpec = MeasureSpec.makeMeasureSpec(lpHeight, MeasureSpec.EXACTLY); } else { childHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); } view.measure(childWidthSpec, childHeightSpec); return view; }
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 w w w .j av a 2 s. c o m*/ * * @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:com.gome.haoyuangong.views.MyViewPageIndicator.java
private void measureView(View child) { ViewGroup.LayoutParams p = child.getLayoutParams(); if (p == null) { p = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); }/*from www . j a v a2 s . co m*/ int childWidthSpec = ViewGroup.getChildMeasureSpec(0, 0 + 0, p.width); int lpHeight = p.height; int childHeightSpec; if (lpHeight > 0) { childHeightSpec = MeasureSpec.makeMeasureSpec(lpHeight, MeasureSpec.EXACTLY); } else { childHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); } child.measure(childWidthSpec, childHeightSpec); }
From source file:com.icloud.listenbook.base.view.DraggableGridViewPager.java
private void measureScrapChild(int position, int widthSpec, int heightSpec, int[] measuredDimension) { if (position < getChildCount()) { View child = getChildAt(position); if (child != null) { ViewGroup.LayoutParams p = (ViewGroup.LayoutParams) child.getLayoutParams(); int childWidthSpec = ViewGroup.getChildMeasureSpec(widthSpec, getPaddingLeft() + getPaddingRight(), p.width);//from w ww . j a v a 2 s . c o m int childHeightSpec = ViewGroup.getChildMeasureSpec(heightSpec, getPaddingTop() + getPaddingBottom(), p.height); child.measure(childWidthSpec, childHeightSpec); measuredDimension[0] = child.getMeasuredWidth(); measuredDimension[1] = child.getMeasuredHeight(); } } }