美文网首页
BaseRecyclerViewAdapterHelper+Vi

BaseRecyclerViewAdapterHelper+Vi

作者: FreakHancock | 来源:发表于2020-10-30 16:09 被阅读0次

    查看ViewPager2源码可以发现

    private RecyclerView.OnChildAttachStateChangeListener enforceChildFillListener() { return new RecyclerView.OnChildAttachStateChangeListener() { @Override public void onChildViewAttachedToWindow(@NonNull View view) { RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) view.getLayoutParams(); if (layoutParams.width != LayoutParams.MATCH_PARENT || layoutParams.height != LayoutParams.MATCH_PARENT) { throw new IllegalStateException( "Pages must fill the whole ViewPager2 (use match_parent)"); } } @Override public void onChildViewDetachedFromWindow(@NonNull View view) { // nothing } };}

    当item的宽或高不为match_parent时就会闪退;

    而当ViewPager2结合使用BaseRecyclerViewAdapterHelper的加载更多模式时,就会偶尔出现闪退现象;

    闪退的最终原因就是:

    LoadMoreModule也是item的一种,而它的布局是默认的,观看源码发现它的高度40dp,而非match_parent,

    所以需要我们自定义LoadMoreView

    将布局的高度修改为match_parent即可。

    之所以我发现这个问题的场景是,运用ViewPager2+BaseRecyclerViewAdapterHelper实现抖音短视频功能

    相关文章

      网友评论

          本文标题:BaseRecyclerViewAdapterHelper+Vi

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