当事件传递到了Activity后首先调用了getWindow().superDispatchTouchEvent(ev)该方法最终调用的是ViewGroup的dispatchTouchEvent,而ViewGroup的事件分发最终是触发了View的dispatchTouchEvent
效果图:
最外层是一个自定义的RefreshRecyclerView(代码在最后面),继承的是SmartRefreshLayout,如下:
<com.common.widget.RefreshRecyclerView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp" />
listView的adpter的核心内容,使用自定义的ScrollView类(MyScrollView、RecyclerViewAtRecycleView在最后面),可以实现整个recycleView横向滑动,关键的是设置这个最大高度,超过的recycleView就可以纵向滑动,并且不与RefreshRecyclerView滑动发生冲突:
<com.common.widget.MyScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:maxHeight="120dp">
<com.common.widget.RecyclerViewAtRecycleView
android:id="@+id/childListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</com.cninct.common.widget.MyScrollView>
最外层的RefreshRecyclerView控件:
/**
* author : yt
* desc : 可统一修改列表的刷新样式,加载更多样式,切换默认空布局文件,可随时替换第三方框架,不影响用到的地方
*/
class RefreshRecyclerView(context: Context, attrs: AttributeSet?) :
SmartRefreshLayout(context, attrs) {
private val mRecyclerView: RecyclerView = RecyclerView(context)
private var onRefreshCallBack: OnRefreshCallBack? = null//刷新回调
private var emptyLayout = 0
/**
* 下拉刷新回调接口
*/
interface OnRefreshCallBack {
fun onRefresh()