最外层是像微信那样的效果,ViewPager里面放了几个Fragment。
Fragment里要使用RecyclerView,但是在RecyclerView上面还有其他的东西,所以我把它们放在LinearLayout里面,再把LinearLayout放在ScrollView里面。这样便实现了我要的效果。
ViewPager可以正常地水平滑动切换,RecyclerView也可以正常地垂直滑动。
问题是:
不管是滑动切换ViewPager还是直接点击下面的按钮切换(就像微信),当切换动画结束,并且RecyclerView部分可见时,如果这时RecyclerView上边缘低于屏幕的上边缘,ScrollView就会跳动一下,RecyclerView的上边缘就正好挨着屏幕上边缘了。
切换过程中RecyclerView不可见时不会发生跳动。
切换过程中RecyclerView上边缘高于屏幕上边缘时,不会发生跳动。
其他原因导致的RecyclerView可见,如Activity的跳转,不会发生跳动。
Fragment布局片段
...
<ScrollView
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>
</ScrollView>
...
阿神2017-04-17 13:59:05
<TextView
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="Text"/>
This View can be implemented as a HeaderView of RecylerView, which can solve the problem just like ListView. The controls appear to slide and align themselves. I think it is caused by the focus change
黄舟2017-04-17 13:59:05
It is not good to nest ListView or RecycleView in ScrollView. The sliding events of the two may conflict, and RecycleView cannot be reused and consumes resources. The best thing is to modify the layout. As mentioned above, you can add HeaderView to implement the layout.
天蓬老师2017-04-17 13:59:05
ok, the scrollview nested listview needs to write the measure method in the listview, and it is impossible to reuse the itemview, which consumes resources. When there are too many items, it will OOM. The best way is to add a headerview.
迷茫2017-04-17 13:59:05
Agree with the answer on the first floor. There is a library here, scrollview, and nested recyclerview itself has many bugs. Adding head to recyclerview is the solution to the problem of adding head to recyclerview. However, if recyclerview is a must It’s a pain when it comes to indispensable items, for example, when used as a grid. At this time, you can be ruthless and give the scrollview a scrollto(0,0). My problem is when switching between show and hide in the fragment. Appeared