RecyclerView inside ScrollView is not working

前端 未结 26 1543
梦如初夏
梦如初夏 2020-11-22 05:37

I\'m trying to implement a layout which contains RecyclerView and ScrollView at the same layout.

Layout template:


    

        
相关标签:
26条回答
  • 2020-11-22 06:33

    Try this. Very late answer. But surely help anyone in future.

    Set your Scrollview to NestedScrollView

    <android.support.v4.widget.NestedScrollView>
     <android.support.v7.widget.RecyclerView>
    </android.support.v7.widget.RecyclerView>
    </android.support.v4.widget.NestedScrollView>
    

    In your Recyclerview

    recyclerView.setNestedScrollingEnabled(false); 
    recyclerView.setHasFixedSize(false);
    
    0 讨论(0)
  • 2020-11-22 06:34

    Another approach to address the issue is to use ConstraintLayout inside ScrollView:

    <ScrollView>
      <ConstraintLayout> (this is the only child of ScrollView)
        <...Some Views...>
        <RecyclerView> (layout_height=wrap_content)
        <...Some Other Views...>
    

    But I would still stick to the androidx.core.widget.NestedScrollView approach, proposed by Yang Peiyong.

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