实现无尽滚动模式RecyclerView
我想创建一个像
public class EndlessScrollAdapter<VH extends ViewHolder>
extends RecyclerView.Adapter<VH> implements RecyclerView.OnScrollListener {
}
Because EndlessScrollAdapter
应该负责数据和滚动事件处理,这是最方便的实现方式。
但是,因为在recyclerview-v7-21.0.3
, OnScrollListener
像这样声明
/**
* An OnScrollListener can be set on a RecyclerView to receive messages
* when a scrolling event has occurred on that RecyclerView.
*
* @see RecyclerView#setOnScrollListener(OnScrollListener)
*/
abstract static public class OnScrollListener {
/**
* Callback method to be invoked when RecyclerView's scroll state changes.
*
* @param recyclerView The RecyclerView whose scroll state has changed.
* @param newState The updated scroll state. One of {@link #SCROLL_STATE_IDLE},
* {@link #SCROLL_STATE_DRAGGING} or {@link #SCROLL_STATE_SETTLING}.
*/
public void onScrollStateChanged(RecyclerView recyclerView, int newState){}
/**
* Callback method to be invoked when the RecyclerView has been scrolled. This will be
* called after the scroll has completed.
*
* @param recyclerView The RecyclerView which scrolled.
* @param dx The amount of horizontal scroll.
* @param dy The amount of vertical scroll.
*/
public void onScrolled(RecyclerView recyclerView, int dx, int dy){}
}
我做不到EndlessScrollAdapter
实施OnScrollListener
.
正如标题所说,有什么充分的理由吗?OnScrollListener
成为一个类而不是一个接口?因为我觉得它应该是一个接口。
我有同样的问题,它绝对是按照设计的,正如这个错误报告中所回答的:
https://code.google.com/p/android/issues/detail?id=79283 https://code.google.com/p/android/issues/detail?id=79283
抽象类允许框架添加新方法而不破坏现有的实现。
还可以在这里找到引入它的差异:
https://android.googlesource.com/platform/frameworks/support/+/cef7b49%5E!/ https://android.googlesource.com/platform/frameworks/support/+/cef7b49%5E!/
此更改将 RecyclerView 添加为滚动相关回调的第一个参数。
它还修复了一个错误,即使用预期的滚动调用滚动回调
量而不是实际的滚动量。
我还将其更改为抽象类而不是接口,以便将来
改变更容易。
就我个人而言,我不确定是否同意这一改变,但就这样吧。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)