Baserecyclerviewadapterhelper: recyclerview横向布局的时候添加headview,设置固定宽度的headview,运行起来却是占满一屏。

Created on 4 Mar 2019  ·  5Comments  ·  Source: CymChad/BaseRecyclerViewAdapterHelper

recyclerview横向布局的时候添加headview,设置固定宽度的headview,运行起来却是占满一屏。

设置横向布局 recyclerview设置match_parent,
mRecyclerviewPhoto.setLayoutManager(new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.HORIZONTAL, false));

自定义的headerview我设置90dp的宽度
myPhotoAdapter.addHeaderView(View.inflate(getApplicationContext(), R.layout.header_vperson_photo, null));

运行起来 headerview却是match_parent

Most helpful comment

mAdapter.addFooterView(view,-1,LinearLayout.HORIZONTAL);
addfooterview有一个重载方法,要设置footerview的方向为horizontal才会使wrap_content生效

All 5 comments

和你一样的问题,我看了库的代码,重写了layoutparam导致的原本的宽高设置无效

和你一样的问题,我看了库的代码,重写了layoutparam导致的原本的宽高设置无效

你解决了没有?

mAdapter.addFooterView(view,-1,LinearLayout.HORIZONTAL);
addfooterview有一个重载方法,要设置footerview的方向为horizontal才会使wrap_content生效

我试过一个TextView没有ViewGroup会导致铺满, 但为TextView设置ViewGroup之后就不会了

@chao9267 正解

Was this page helpful?
0 / 5 - 0 ratings