美文网首页
RecyclerView最大高度

RecyclerView最大高度

作者: 细雨么么 | 来源:发表于2020-02-26 16:30 被阅读0次

先贴两个相关链接。侵删
https://www.jianshu.com/p/cd4f13b01e2c

https://blog.csdn.net/weixiao_812/article/details/89518253

public class MyRecyclerView extends RecyclerView {


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

    public MyRecyclerView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public MyRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onMeasure(int widthSpec, int heightSpec) {
        if (getChildCount() > 5) {
            View child = getChildAt(0);
            child.measure(widthSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
            int height = child.getMeasuredHeight() + getPaddingTop() + getPaddingBottom();
            setMeasuredDimension(widthSpec, height * 5);
        } else {
            super.onMeasure(widthSpec, heightSpec);
        }


    }
}

相关文章

网友评论

      本文标题:RecyclerView最大高度

      本文链接:https://www.haomeiwen.com/subject/psebchtx.html