Android--NestedScrollView

这个东西的作用是用于拉动时的。举个例子,你的界面上有轮播图和一个recylerview的时候。当你的recyclerview有一定的数量需要往下拉时。你就会发现,轮播图还在那里,但是列表往下拉了。嗯,直接上代码看下吧:

   <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                
                <androidx.viewpager.widget.ViewPager
                    android:id="@+id/vp_empty"
                    android:layout_width="match_parent"
                    android:layout_height="150dp" />
    
            </RelativeLayout>
            
            <androidx.recyclerview.widget.RecyclerView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/recycler_empty"/>
                
        </LinearLayout>

    </androidx.core.widget.NestedScrollView>

但是这里要注意的点时什么呢,也就是在源码上NestedScrollView是只能有一个孩子,如果有多个孩子就会报错,所以,当你有很多布局时,你就需要用一层viewgroup包裹住。

原创文章 158 获赞 2 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_43616001/article/details/104979807