美文网首页
ScrollView 嵌套RecyclerView 设置空数据V

ScrollView 嵌套RecyclerView 设置空数据V

作者: 越过山丘1024 | 来源:发表于2020-04-22 11:12 被阅读0次

    当RecyclerView设置的数据存在空白的情况时,需要显示EmptyView时,发现EmptyView不能填充满RecyclerView,这时候设置“fill_parent”或者“match_parent”是不管用的,因为当NestedScrollView没有设置fillVeewport为true时, 里面的元素(比如RecyclerView)会按照wrap_content来计算。

    这时候只需要给NestedScrollView设置 android:fillViewport="true"即可解决问题。

         <androidx.core.widget.NestedScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fillViewport="true">
    
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical">
                        <TextView
                            android:id="@+id/tv_1"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginBottom="5dp"
                            android:padding="15dp"
                            app:text="测试布局"/>
    
                    </LinearLayout>
    
                    <androidx.recyclerview.widget.RecyclerView
                        android:id="@+id/rv_list"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent />
    
                </LinearLayout>
    
            </androidx.core.widget.NestedScrollView>
    

    另外如果只使用NestedScrollView替换了ScrollView,建议java代码中设置recyclerView.setNestedScrollingEnabled(false);如果不设置那么你的App滑动流畅度就像得了老年痴呆一样,和自定义FullyLinearLayoutManager解决方案的滑动流畅度有的一拼。

    相关文章

      网友评论

          本文标题:ScrollView 嵌套RecyclerView 设置空数据V

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