Horizontal RecyclerView follows first item height with wrap_content

前端 未结 3 1458
佛祖请我去吃肉
佛祖请我去吃肉 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);
            }
        }
    });
    
    0 讨论(0)
  • 2020-12-16 01:06

    Since this question is getting quite a lot of traction and I only posted my personal solution in the comments I'll submit an answer as well.

    --

    I decided to use Google's Flexbox layout library to achieve what I wanted. It's very customizable and I would recommend it to people who are trying to solve similar problems.

    0 讨论(0)
  • 2020-12-16 01:17

    change your imageview height as wrap_content. I'm not sure, try like that.

    0 讨论(0)
提交回复
热议问题