首页 > 其他分享 >RecycleView根据内容自适应高度,最大高度限制

RecycleView根据内容自适应高度,最大高度限制

时间:2022-11-04 12:01:01浏览次数:39  
标签:int super RecycleView maxHeight 适应 heightSize context 高度限制 public


前言

recylceView 日常开发经常使用到,默认高度自适应,如何增加最大高度限制如下:

public class MeasureLinearLayoutManager extends LinearLayoutManager {
private int maxHeight;

public MeasureLinearLayoutManager(Context context) {
super(context);
}

public MeasureLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
super(context, orientation, reverseLayout);
}

public MeasureLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}

public int getMaxHeight() {
return maxHeight;
}

public void setMaxHeight(int maxHeight) {
this.maxHeight = maxHeight;
}

@Override
public void setMeasuredDimension(int widthSize, int heightSize) {
if (maxHeight == 0) {
super.setMeasuredDimension(widthSize, heightSize);
} else {
super.setMeasuredDimension(
widthSize, heightSize < maxHeight ? heightSize : maxHeight);
}
}
}


标签:int,super,RecycleView,maxHeight,适应,heightSize,context,高度限制,public
From: https://blog.51cto.com/u_15861646/5823446

相关文章