androidx.recyclerview.widget.RecyclerView.LayoutParams Java Examples

The following examples show how to use androidx.recyclerview.widget.RecyclerView.LayoutParams. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BaseQuickAdapter.java    From BaseProject with Apache License 2.0 6 votes vote down vote up
/**
 * 对适配器中的itemView任何View(含itemView本身)
 * 进入relayout
 * @param customLayoutParams 自定义的布局参数
 * @param assignTagId 指定的要给View标识为是否已经relayout了
 * @param anyView 要relayout的任何View
 * @param isTheAdapteItemView 是否为适配器的itemView本身
 * @return true:relayout了; false:未进行relayout或者已经relayout过了
 */
protected boolean relayoutAnyView(@Nullable ViewGroup.LayoutParams customLayoutParams, @IdRes int assignTagId, View anyView,boolean isTheAdapteItemView) {
    if (anyView == null) {
        return false;//代表本次不去relayout了
    }
    Object relayoutTag = anyView.getTag(assignTagId);
    if (relayoutTag != null) {//已经relayout了当前的view,则不进行relayout了
        return false;//代表本次不去relayout了
    }
    // Q:2019/10/24 ??要回调开始relayout了吗?A:还是回调吧,如果有额外的处理,则给机会处理,然后最后统一setLayoutParams
    startRelayoutAnyView(isTheAdapteItemView,anyView);
    anyView.setTag(assignTagId, "relayouted");
    if (customLayoutParams != null) {
        anyView.setLayoutParams(customLayoutParams);
    }
    return true;//代表本次relayout了
}
 
Example #2
Source File: MonthsPagerAdapter.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
  LinearLayout container =
      (LinearLayout)
          LayoutInflater.from(viewGroup.getContext())
              .inflate(R.layout.mtrl_calendar_month_labeled, viewGroup, false);

  if (MaterialDatePicker.isFullscreen(viewGroup.getContext())) {
    container.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, itemHeight));
    return new ViewHolder(container, /* showLabel= */ true);
  } else {
    return new ViewHolder(container, /* showLabel= */ false);
  }
}
 
Example #3
Source File: BaseQuickAdapter.java    From BaseProject with Apache License 2.0 5 votes vote down vote up
/**
 * added by fee 2019-07-11:
 * <P>注:该方法主要是用来relayout适配的itemView布局,依赖的前提条件为外部指定了itemView的宽、高</P>
 * 为了满足某些场景下,需要通过外部来重新指定item view的宽、高,则在{convert(xx,xx)}
 * 需要重新设置item view的布局参数
 * @param assignTagId 所指定的给 theItemView setTag()用于标记已经relayout过的
 * @param theItemView 当前的item 视图
 * @return true:重置了itemview布局
 */
protected boolean relayoutTheItemView(@IdRes int assignTagId, View theItemView) {
    if (theAssignItemHeight == 0 && theAssignItemWidth == 0) {
        return false;
    }
    if (theItemView == null) {
        return false;
    }
    Object relayoutTag = theItemView.getTag(assignTagId);
    if (relayoutTag != null) {//已经relayout了当前的item view,则不进行relayout了
        return false;
    }
    startRelayoutItemView(theItemView);//这里回调出去主要是为了如果有额外的处理,则给机会处理,然后最后统一setLayoutParams
    ViewGroup.LayoutParams vlp = theItemView.getLayoutParams();
    if (vlp == null) {
        vlp = new ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    }
    if (theAssignItemWidth > 0) {//一般宽较容易确定
        vlp.width = theAssignItemWidth;
    }
    if (theAssignUiDesignWidthRatio != 0 && theAssignUiDesignHeightRatio != 0 && theAssignItemWidth > 0) {
        //h实 = w实 * h设计高占比 /w设计宽占比:即等比缩放itemView宽高
        theAssignItemHeight = theAssignItemWidth * theAssignUiDesignHeightRatio / theAssignUiDesignWidthRatio;
    }
    if (theAssignItemHeight > 0) {
        vlp.height = theAssignItemHeight;
    }
    theItemView.setTag(assignTagId, "relayouted");
    theItemView.setLayoutParams(vlp);
    return true;
}
 
Example #4
Source File: BaseQuickAdapter.java    From BaseProject with Apache License 2.0 5 votes vote down vote up
protected boolean relayoutTheItemView(ViewGroup.LayoutParams customLayoutParams, @IdRes int assignTagId, View theItemView) {
    if (customLayoutParams == null || theItemView == null) {
        return false;
    }
    Object relayoutTag = theItemView.getTag(assignTagId);
    if (relayoutTag != null) {//已经relayout了当前的item view,则不进行relayout了
        return false;
    }
    startRelayoutItemView(theItemView);
    theItemView.setTag(assignTagId,"relayouted");
    theItemView.setLayoutParams(customLayoutParams);
    return true;
}
 
Example #5
Source File: LinearLayoutInfo.java    From litho with Apache License 2.0 4 votes vote down vote up
@Override
public LayoutParams generateDefaultLayoutParams() {
  return getOrientation() == OrientationHelper.VERTICAL
      ? new RecyclerView.LayoutParams(MATCH_PARENT, WRAP_CONTENT)
      : new RecyclerView.LayoutParams(WRAP_CONTENT, MATCH_PARENT);
}
 
Example #6
Source File: SlideItemAnimator.java    From FlexibleAdapter with Apache License 2.0 4 votes vote down vote up
public int getWidth(View itemView) {
    return itemView.getMeasuredWidth() + itemView.getPaddingRight() + ((LayoutParams) itemView.getLayoutParams()).rightMargin;
}
 
Example #7
Source File: BaseQuickAdapter.java    From BaseProject with Apache License 2.0 3 votes vote down vote up
/**
 * When set to true, the item will layout using all span area. That means, if orientation
 * is vertical, the view will have full width; if orientation is horizontal, the view will
 * have full height.
 * if the hold view use StaggeredGridLayoutManager they should using all span area
 *
 * @param holder True if this item should traverse all spans.
 */
protected void setFullSpan(RecyclerView.ViewHolder holder) {
    if (holder.itemView.getLayoutParams() instanceof StaggeredGridLayoutManager.LayoutParams) {
        StaggeredGridLayoutManager.LayoutParams params = (StaggeredGridLayoutManager.LayoutParams) holder
                .itemView.getLayoutParams();
        params.setFullSpan(true);
    }
}