RecyclerView,ScrollView等代码定义最大高度
public class MyRecyclerView extends RecyclerView {
public int mMaxHeight=0;
public MyRecyclerView(@NonNull @NotNull Context context) {
super(context);
}
public MyRecyclerView(@NonNull @NotNull Context context, @Nullable @org.jetbrains.annotations.Nullable AttributeSet attrs) {
super(context, attrs);
}
public MyRecyclerView(@NonNull @NotNull Context context, @Nullable @org.jetbrains.annotations.Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (mMaxHeight > 0) {
heightMeasureSpec = MeasureSpec.makeMeasureSpec(mMaxHeight, MeasureSpec.AT_MOST);
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
public void setmMaxHeight(int max){
this.mMaxHeight=max;
invalidate();
}
}