标签:getc idt line 情况 pos child targe 固定 eal
使用时,请注意2点情况:
/** * 自适应列表View在到指定数量item后固定高度, * * @param targetNum */ private void adaptiveRecyclerViewHeight(int targetNum) { mFamilyListRecyclerview.setLayoutManager(new LinearLayoutManager(getContext()) { @Override public void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state, int widthSpec, int heightSpec) { int count = state.getItemCount(); if (count > 0) { if (count > targetNum) { count = targetNum; } int realHeight = 0; int realWidth = 0; for (int i = 0; i < count; i++) { View view = recycler.getViewForPosition(0); if (view != null) { measureChild(view, widthSpec, heightSpec); int measuredWidth = View.MeasureSpec.getSize(widthSpec); int measuredHeight = view.getMeasuredHeight(); realWidth = realWidth > measuredWidth ? realWidth : measuredWidth; realHeight = realHeight + measuredHeight; } } setMeasuredDimension(realWidth, realHeight); } else { super.onMeasure(recycler, state, widthSpec, heightSpec); } } }); }
END
标签:getc idt line 情况 pos child targe 固定 eal
原文地址:https://www.cnblogs.com/guanxinjing/p/12584134.html