最近在项目中产品提出一个需求要首页改版做吸顶效果。上面是频道和banner轮播,吸顶部分是tab,下面是recyclerview列表。
这里使用的CoordinatorLayout+AppBarLayout+CollapsingToolbarLayout协调布局做成了那样的效果。但是遇到一个问题是banner轮播图向上滑动滑不动。刚开始以为banner跟外面的滑动冲突,重写banner的dispatchTouchEvent方法进行拦截也不行,后来发现刚进来首页的时候banner是可以滑动的但是一滑动下面的列表的时候banner轮播就不行了,失去了向上滑动的事件了,但是可以向下滑动,这就很奇怪了,当时就想是不是跟下面的是recyclerview冲突了,但是使劲的滑动上面的banner图发现可以稍微滑动一点,就是好像没有滑动的触摸焦点一样。
然后我在banner外层嵌套了一层NestedScrollView竟然可以了。
<android.support.v4.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"
app:layout_collapseMode="none">
<include layout="@layout/layout_item_new_channel" />
<include
layout="@layout/layout_item_banner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
困扰半天多的问题终于解决,先记录下来!然后再研究具体什么原因。