我构建了一个同时需要 pulltorefresh 和 stickylistHeaders 的应用程序。我已经在应用程序中实现了 pulltorefresh,但无法使其与 stickyListHeaders 一起使用。是否可以合并这两个库? 或者还有其他选择吗?有什么想法吗?
最佳答案
我的实现在更新两个库后也被破坏了。这是我的快速修复以使其再次运行。 欢迎提出任何建议和改进!
创建一个新类并扩展 SticklistListHeadersListView 并从 ActionBar-PullToRefresh 实现 ViewDelegate 接口(interface):
public class PtrStickyListHeadersListView extends StickyListHeadersListView implements ViewDelegate { public PtrStickyListHeadersListView(Context context) { super(context); } public PtrStickyListHeadersListView(Context context, AttributeSet attrs) { super(context, attrs); } public PtrStickyListHeadersListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override public boolean isReadyForPull(View view, float v, float v2) { View childView = getWrappedList().getChildAt(0); int top = (childView == null) ? 0 : childView.getTop(); return top >= 0; } }
并在您的
layout.xml
中替换<se.emilsjolander.stickylistheaders.StickyListHeadersListView ...>
与
<com.yourapp.package.foo.PtrStickyListHeadersListView ...>
最后,添加委托(delegate):(
listView
是 PtrStickyListHeadersListView 的实例)ActionBarPullToRefresh.from(getActivity()) // We need to insert the PullToRefreshLayout into the Fragment 's ViewGroup .insertLayoutInto(viewGroup) // We need to mark the ListView and it 's Empty View as pullable // This is because they are not dirent children of the ViewGroup .theseChildrenArePullable(R.id.your_list_id) // We can now complete the setup as desired .listener(...) .useViewDelegate(PtrStickyListHeadersListView.class, listView) .setup(mPullToRefreshLayout);
关于android - 是否可以将 stickylistviewheader 与 crisbanes pulltorefresh 合并?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20143008/