當前位置: 首頁>>代碼示例>>Java>>正文


Java ViewGroup.getChildMeasureSpec方法代碼示例

本文整理匯總了Java中android.view.ViewGroup.getChildMeasureSpec方法的典型用法代碼示例。如果您正苦於以下問題:Java ViewGroup.getChildMeasureSpec方法的具體用法?Java ViewGroup.getChildMeasureSpec怎麽用?Java ViewGroup.getChildMeasureSpec使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.view.ViewGroup的用法示例。


在下文中一共展示了ViewGroup.getChildMeasureSpec方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: cacaheHeaderView

import android.view.ViewGroup; //導入方法依賴的package包/類
private void cacaheHeaderView(RecyclerView parent, int position, ViewParams view) {
        if (!mHeaderCache.containsKey(position)) {
            final RecyclerView.ViewHolder holder = mAdapter.onCreateHeaderViewHolder(parent, position);
            final View header = holder.itemView;
            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(), view.getMeasuredWidth());
            int childHeight = ViewGroup.getChildMeasureSpec(heightSpec,
                    parent.getPaddingTop() + parent.getPaddingBottom(), view.getMeasuredHeight());
//            Log.e("headerParams", position + " " + view.getMeasuredWidth() + "  " + view.getMeasuredHeight());
            header.measure(childWidth, childHeight);
            header.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
            mHeaderCache.put((long) position, holder);
        }
    }
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:20,代碼來源:StickyAnyDecoration.java

示例2: measureView

import android.view.ViewGroup; //導入方法依賴的package包/類
public static void measureView(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);
}
 
開發者ID:jeasinlee,項目名稱:AndroidBasicLibs,代碼行數:17,代碼來源:ViewUtils.java

示例3: getHeader

import android.view.ViewGroup; //導入方法依賴的package包/類
@Override
protected HeaderViewHolder getHeader(RecyclerView parent, StickyHeaderAdapter stickyAdapter, int position) {
  HeaderViewHolder viewHolder = adapter.onCreateLastSeenViewHolder(parent);
  adapter.onBindLastSeenViewHolder(viewHolder, 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(), viewHolder.itemView.getLayoutParams().width);
  int childHeight = ViewGroup.getChildMeasureSpec(heightSpec, parent.getPaddingTop() + parent.getPaddingBottom(), viewHolder.itemView.getLayoutParams().height);

  viewHolder.itemView.measure(childWidth, childHeight);
  viewHolder.itemView.layout(0, 0, viewHolder.itemView.getMeasuredWidth(), viewHolder.itemView.getMeasuredHeight());

  return viewHolder;
}
 
開發者ID:CableIM,項目名稱:Cable-Android,代碼行數:17,代碼來源:ConversationAdapter.java

示例4: measureScrapChildWidth

import android.view.ViewGroup; //導入方法依賴的package包/類
private void measureScrapChildWidth(View child, int position, int heightMeasureSpec) {
	LayoutParams p = (LayoutParams) child.getLayoutParams();
	if (p == null) {
		p = (AbsHListView.LayoutParams) generateDefaultLayoutParams();
		child.setLayoutParams(p);
	}
	p.viewType = mAdapter.getItemViewType(position);
	p.forceAdd = true;

	int childHeightSpec = ViewGroup.getChildMeasureSpec(heightMeasureSpec, mListPadding.top + mListPadding.bottom,
			p.height);
	int lpWidth = p.width;
	int childWidthSpec;
	if (lpWidth > 0) {
		childWidthSpec = MeasureSpec.makeMeasureSpec(lpWidth, MeasureSpec.EXACTLY);
	} else {
		childWidthSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
	}
	child.measure(childWidthSpec, childHeightSpec);
}
 
開發者ID:junchenChow,項目名稱:exciting-app,代碼行數:21,代碼來源:HListView.java

示例5: measureScrapChild

import android.view.ViewGroup; //導入方法依賴的package包/類
private void measureScrapChild(RecyclerView.Recycler recycler, int position, int widthSpec,
                               int heightSpec, int[] measuredDimension) {
    try {
        View view = recycler.getViewForPosition(0);//fix 動態添加時報IndexOutOfBoundsException

        if (view != null) {
            RecyclerView.LayoutParams p = (RecyclerView.LayoutParams) view.getLayoutParams();

            int childWidthSpec = ViewGroup.getChildMeasureSpec(widthSpec,
                    getPaddingLeft() + getPaddingRight(), p.width);

            int childHeightSpec = ViewGroup.getChildMeasureSpec(heightSpec,
                    getPaddingTop() + getPaddingBottom(), p.height);

            view.measure(childWidthSpec, childHeightSpec);
            measuredDimension[0] = view.getMeasuredWidth() + p.leftMargin + p.rightMargin;
            measuredDimension[1] = view.getMeasuredHeight() + p.bottomMargin + p.topMargin;
            recycler.recycleView(view);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
    }
}
 
開發者ID:yiwent,項目名稱:Mobike,代碼行數:25,代碼來源:FullyLinearLayoutManager.java

示例6: measureItem

import android.view.ViewGroup; //導入方法依賴的package包/類
private void measureItem(View item) {
    ViewGroup.LayoutParams lp = item.getLayoutParams();
    if (lp == null) {
        lp = new LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        item.setLayoutParams(lp);
    }
    int wspec = ViewGroup.getChildMeasureSpec(mWidthMeasureSpec, getListPaddingLeft()
            + getListPaddingRight(), lp.width);
    int hspec;
    if (lp.height > 0) {
        hspec = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY);
    } else {
        hspec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    }
    item.measure(wspec, hspec);
}
 
開發者ID:bunnyblue,項目名稱:NoticeDog,代碼行數:17,代碼來源:DragSortListView.java

示例7: measureViewHeight

import android.view.ViewGroup; //導入方法依賴的package包/類
protected static int measureViewHeight(View view) {
    ViewGroup.LayoutParams p = view.getLayoutParams();
    if (p == null) {
        p = new ViewGroup.LayoutParams(MATCH_PARENT,WRAP_CONTENT);
    }
    int childHeightSpec;
    int childWidthSpec = ViewGroup.getChildMeasureSpec(0, 0, p.width);
    if (p.height > 0) {
        childHeightSpec = MeasureSpec.makeMeasureSpec(p.height, MeasureSpec.EXACTLY);
    } else {
        childHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    }
    view.measure(childWidthSpec, childHeightSpec);
    return view.getMeasuredHeight();
}
 
開發者ID:penghuanliang,項目名稱:Rxjava2.0Demo,代碼行數:16,代碼來源:RefreshContentWrapper.java

示例8: measureView

import android.view.ViewGroup; //導入方法依賴的package包/類
/**
 * 測量視圖尺寸
 *
 * @param view 視圖
 * @return arr[0]: 視圖寬度, arr[1]: 視圖高度
 */
public static int[] measureView(View view) {
    ViewGroup.LayoutParams lp = view.getLayoutParams();
    if (lp == null) {
        lp = new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT
        );
    }
    int widthSpec = ViewGroup.getChildMeasureSpec(0, 0, lp.width);
    int lpHeight = lp.height;
    int heightSpec;
    if (lpHeight > 0) {
        heightSpec = View.MeasureSpec.makeMeasureSpec(lpHeight, View.MeasureSpec.EXACTLY);
    } else {
        heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    }
    view.measure(widthSpec, heightSpec);
    return new int[]{view.getMeasuredWidth(), view.getMeasuredHeight()};
}
 
開發者ID:ifadai,項目名稱:AndroidThemeChange,代碼行數:26,代碼來源:SizeUtils.java

示例9: measureHeader

import android.view.ViewGroup; //導入方法依賴的package包/類
/**
 * measure header view's width and height
 *
 * @param headerView
 */
private void measureHeader(View headerView,int height) {
    LayoutParams p = (LayoutParams) headerView.getLayoutParams();
    if (p == null) {
        int h = height == 0 ? ViewGroup.LayoutParams.WRAP_CONTENT : height;
        p = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, h);
    }else if(height != 0){
        p.height = height;
    }
    headerView.setLayoutParams(p);
    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);
    }
    headerView.measure(childWidthSpec, childHeightSpec);
}
 
開發者ID:jpaijh,項目名稱:TYT,代碼行數:25,代碼來源:ListZoomView.java

示例10: measureView

import android.view.ViewGroup; //導入方法依賴的package包/類
/**
 * 測量View的尺寸<br/>
 * 由於Android你中View需要測量後才能得到具體的尺寸數據<br/>
 * 但是我們在使用中,通常都是初始化就需要得到尺寸數據<br/>
 * 因此提供該工具方法,隻要對需要尺寸數據的View執行該方法<br/>
 * 然後該View就可以取到尺寸信息。
 *
 * @param child
 */
public static void measureView(View child) {
    ViewGroup.LayoutParams lp = child.getLayoutParams();
    if (lp == null) {
        lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    }
    // View的寬度信息
    int childMeasureWidth = ViewGroup.getChildMeasureSpec(0, 0, lp.width);
    int childMeasureHeight;
    if (lp.height > 0) {
        // 最後一個參數表示:適合、匹配
        childMeasureHeight = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY);
    } else {
        childMeasureHeight = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); // 未指定
    }
    //
    child.measure(childMeasureWidth, childMeasureHeight);
}
 
開發者ID:ymqq,項目名稱:CommonFramework,代碼行數:27,代碼來源:ViewUtils.java

示例11: measureScrapChild

import android.view.ViewGroup; //導入方法依賴的package包/類
private void measureScrapChild(RecyclerView.Recycler recycler, int position, int widthSpec, int heightSpec, int[] measuredDimension) {

        View view = recycler.getViewForPosition(0);

        if (view != null) {

            RecyclerView.LayoutParams p = (RecyclerView.LayoutParams) view.getLayoutParams();

            int childWidthSpec = ViewGroup.getChildMeasureSpec(widthSpec,
                    getPaddingLeft() + getPaddingRight(), p.width);
            int childHeightSpec = ViewGroup.getChildMeasureSpec(heightSpec,
                    getPaddingTop() + getPaddingBottom(), p.height);

            view.measure(childWidthSpec, childHeightSpec);

            measuredDimension[0] = view.getMeasuredWidth() + p.leftMargin + p.rightMargin;
            measuredDimension[1] = view.getMeasuredHeight() + p.bottomMargin + p.topMargin;

            Rect decoratorRect=new Rect();
            calculateItemDecorationsForChild(view,decoratorRect);
            measuredDimension[0]+=decoratorRect.left;
            measuredDimension[0]+=decoratorRect.right;
            measuredDimension[1]+=decoratorRect.top;
            measuredDimension[1]+=decoratorRect.bottom;

            recycler.recycleView(view);
        }
    }
 
開發者ID:Luodian,項目名稱:Shared-Route,代碼行數:29,代碼來源:MainActivity.java

示例12: measureChild

import android.view.ViewGroup; //導入方法依賴的package包/類
/**
 * Measure the provided child.
 *
 * @param child The child.
 */
private void measureChild(View child) {
    LayoutParams childLayoutParams = getLayoutParams(child);
    int childHeightSpec = ViewGroup.getChildMeasureSpec(mHeightMeasureSpec, getPaddingTop() + getPaddingBottom(), childLayoutParams.height);

    int childWidthSpec;
    if (childLayoutParams.width > 0) {
        childWidthSpec = MeasureSpec.makeMeasureSpec(childLayoutParams.width, MeasureSpec.EXACTLY);
    } else {
        childWidthSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    }

    child.measure(childWidthSpec, childHeightSpec);
}
 
開發者ID:zqHero,項目名稱:rongyunDemo,代碼行數:19,代碼來源:HorizontalListView.java

示例13: getHeader

import android.view.ViewGroup; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private RecyclerView.ViewHolder getHeader(RecyclerView parent, int position) {

    final long key = mAdapter.getHeaderId(position);
    if (mHeaderCache.indexOfKey(key) >= 0) {

        return mHeaderCache.get(key);
    } else {

        final RecyclerView.ViewHolder holder = mAdapter.onCreateHeaderViewHolder(parent);
        final View header = holder.itemView;

        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;
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:31,代碼來源:StickyHeaderDecoration.java

示例14: getHeader

import android.view.ViewGroup; //導入方法依賴的package包/類
private RecyclerView.ViewHolder getHeader(RecyclerView parent, int position) {
    long key = position;
    if (mHeaderCache.containsKey(key)) {
        return mHeaderCache.get(key);
    } else {
        final RecyclerView.ViewHolder holder = mAdapter.onCreateHeaderViewHolder(parent, position);
        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;
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:28,代碼來源:StickyHeaderDecoration.java

示例15: getHeader

import android.view.ViewGroup; //導入方法依賴的package包/類
private RecyclerView.ViewHolder getHeader(RecyclerView parent, int position) {
    final long key = mListener.getHeaderId(position);

    if (mHeaderCache.containsKey(key)) {
        return mHeaderCache.get(key);
    } else {
        final RecyclerView.ViewHolder holder = mListener.onCreateHeaderViewHolder(parent);
        final View header = holder.itemView;

        //noinspection unchecked
        mListener.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;
    }
}
 
開發者ID:yedashen,項目名稱:UltimateRecyclerView,代碼行數:29,代碼來源:StickyHeaderDecoration.java


注:本文中的android.view.ViewGroup.getChildMeasureSpec方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。