当前位置: 首页>>代码示例>>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;未经允许,请勿转载。