Horizontal RecyclerView follows first item height with wrap_content

前端 未结 3 1459
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-16 00:32

I have a RecyclerView with a horizontal layout. The height of the individual adapter items can depend on the content of the item.

So in theory it can lo

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-16 00:56

    Try this. Anyway, did you solve your problem?

    mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
            final int newHeight = recyclerView.getMeasuredHeight();
            if (0 != newHeight && minHeight < newHeight) {
            // keep track the height and prevent recycler view optimizing by resizing
                minHeight = newHeight;
                recyclerView.setMinimumHeight(minHeight);
            }
        }
    });
    

提交回复
热议问题