RecyclerView inside ScrollView, some items are not shown

前端 未结 2 1396
忘了有多久
忘了有多久 2021-01-03 22:53

I had a RecyclerView in ScrollView like this:



    &l         


        
相关标签:
2条回答
  • 2021-01-03 23:31

    I found the solution myself: replace ScrollView with NestedScrollView and keep recyclerView.setNestedScrollingEnabled(false). I don't know if this is what NestedScrollView is made for but it works.

    NOTICE:

    1. NestedScrollView is not a child of ScrollView but of FrameLayout.
    2. This solution will also bring some bugs with self-simulated adjustResize.
    0 讨论(0)
  • 2021-01-03 23:51

    The best solution is to keep multiple Views in a Single View / View Group and then keep that one view in the SrcollView. ie.

    Format -

    <ScrollView> 
      <Another View>
           <RecyclerView>
           <TextView>
           <And Other Views>
      </Another View>
    </ScrollView>
    

    Eg.

    <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
            <TextView           
                  android:text="any text"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"/>
    
    
            <TextView           
                  android:text="any text"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"/>
     </ScrollView>
    

    Another Eg. of ScrollView with multiple Views

    <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:orientation="vertical"
                android:layout_weight="1">
    
                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/imageView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="#FFFFFF"
                    />
    
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingHorizontal="10dp"
                    android:orientation="vertical">
    
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/CategoryItem"
                        android:textSize="20sp"
                        android:textColor="#000000"
                        />
    
                    <TextView
                        android:textColor="#000000"
                        android:text="₹1000"
                        android:textSize="18sp"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"/>
                    <TextView
                        android:textColor="#000000"
                        android:text="so\nugh\nos\nghs\nrgh\n
                        sghs\noug\nhro\nghreo\nhgor\ngheroh\ngr\neoh\n
                        og\nhrf\ndhog\n
                        so\nugh\nos\nghs\nrgh\nsghs\noug\nhro\n
                        ghreo\nhgor\ngheroh\ngr\neoh\nog\nhrf\ndhog"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"/>
    
                 </LinearLayout>
    
            </LinearLayout>
    
    </ScrollView>
    
    0 讨论(0)
提交回复
热议问题