最外层是像微信那样的效果,ViewPager里面放了几个Fragment。
Fragment里要使用RecyclerView,但是在RecyclerView上面还有其他的东西,所以我把它们放在LinearLayout里面,再把LinearLayout放在ScrollView里面。这样便实现了我要的效果。
ViewPager可以正常地水平滑动切换,RecyclerView也可以正常地垂直滑动。
问题是:
不管是滑动切换ViewPager还是直接点击下面的按钮切换(就像微信),当切换动画结束,并且RecyclerView部分可见时,如果这时RecyclerView上边缘低于屏幕的上边缘,ScrollView就会跳动一下,RecyclerView的上边缘就正好挨着屏幕上边缘了。
切换过程中RecyclerView不可见时不会发生跳动。
切换过程中RecyclerView上边缘高于屏幕上边缘时,不会发生跳动。
其他原因导致的RecyclerView可见,如Activity的跳转,不会发生跳动。
Fragment布局片段
<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">
<TextView
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="Text"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/rcv_draw_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_bottom_line"
/>
</LinearLayout>
</NestedScrollview>
...
可能有人说添加头布局,但是我添加头布局之后会出问题,左右宽度会压缩,我如果不添加头布局还有什么解决方式吗?急求,谢谢。如果有人遇到这样的问题又解决了的话请加QQ283006603
Tidak disyorkan untuk menyarangkan RecyclerView di dalam ScrollView. Akan ada masalah semasa mengira ketinggian, dan prestasi juga menjadi masalah. Lebar RecyclerView adalah penuh lebar kanan dikawal dalam item
Jika anda berkeras untuk berbuat demikian, cuba ganti kaedah onMeasure RecyclerView