美文网首页
ScrollView嵌套RecycleView时,Recycle

ScrollView嵌套RecycleView时,Recycle

作者: 光羽隼 | 来源:发表于2017-12-20 14:02 被阅读0次

RecycleView布局外边再嵌套一层RelativeLayout布局;

今天在搬砖的时候,我发现ScrollView内部嵌套RecycleVIew的时候,RecycleView老是只能显示两行,网上很多工友都提出需要重写LinearLayoutManager,我当然是选择相信的,重写了之后并没有用。
后来又有工友说需要在RecycleView外层包裹一层RelativeLayout。加上去之后果然有效。很棒!
原本我的布局是这样的:

<RelativeLayout
    ....>

     <RelativeLayout
        ...>
     </RelativeLayout>

     <ScrollView
          ...>
         //如果ScrollView内部不止一个控件,那么就需要用一个布局包裹,
         //我这里选择了LinearLayout,事实证明是错误的;
          <LinearLayout
              ...>
                 .....
                 .....
                 .....
                 //在RecycleVIew外层包裹一层ScrollView是为了让RecycleView滑动的更流畅。
                 <ScrollView
                       ...>

                        <RecycleView
                           ...>

                       </RecycleView>

                 </ScrollView>

          </LinearLayout>

    </ScrollView>

</RelativeLayout>

这样的布局显示出来的的RecycleVIew条目只有两个,不论怎样重写LinearLayoutManager都没用。
所以我就在RecycleVIew外层又添加了一层RelativeLayout

<RelativeLayout
    ....>

     <RelativeLayout
        ...>
     </RelativeLayout>

     <ScrollView
          ...>
         //如果ScrollView内部不止一个控件,那么就需要用一个布局包裹,
         //我这里选择了LinearLayout,事实证明是错误的;
          <LinearLayout
              ...>
                 .....
                 .....
                 .....
                 //在RecycleVIew外层包裹一层ScrollView是为了让RecycleView滑动的更流畅。
                 <ScrollView
                       ...>
                     <RelativeLayout
                         ...>

                        <RecycleView
                           ...>

                       </RecycleView>

                      </RelativeLayout
                 </ScrollView>

          </LinearLayout>

    </ScrollView>

</RelativeLayout>

这样成功了,但是好像嵌套的有点多了,出现这样的问题是不是外层的LinearLayout的问题呢?于是我将外层的LinearLayout改成了RelativeLayout:

<RelativeLayout
    ....>

     <RelativeLayout
        ...>
     </RelativeLayout>
     <ScrollView
          ...>
         //如果ScrollView内部不止一个控件,那么就需要用一个布局包裹,
         //我这里选择了LinearLayout,事实证明是错误的;
          <RelativeLayout
              ...>
                 .....
                 .....
                 .....
                 //在RecycleVIew外层包裹一层ScrollView是为了让RecycleView滑动的更流畅。
                 <ScrollView
                       ...>
                        <RecycleView
                           ...>

                       </RecycleView>
                 </ScrollView>

         </RelativeLayout>

    </ScrollView>

</RelativeLayout>

这样问题解决,内部原因,等我稍后查一下。为什么ScrollView嵌套RecycleViewLinearLayoutRelativeLayout的包裹会不同效果

相关文章

网友评论

      本文标题:ScrollView嵌套RecycleView时,Recycle

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