android - 是否可以将 stickylistviewheader 与 crisbanes pulltorefresh 合并?

标签 android user-interface pull-to-refresh

我构建了一个同时需要 pulltorefresh 和 stickylistHeaders 的应用程序。我已经在应用程序中实现了 pulltorefresh,但无法使其与 stickyListHeaders 一起使用。是否可以合并这两个库? 或者还有其他选择吗?有什么想法吗?

最佳答案

我的实现在更新两个库后也被破坏了。这是我的快速修复以使其再次运行。 欢迎提出任何建议和改进!

  1. 创建一个新类并扩展 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;
        }
    }
    
  2. 并在您的 layout.xml 中替换

    <se.emilsjolander.stickylistheaders.StickyListHeadersListView
            ...>
    

    <com.yourapp.package.foo.PtrStickyListHeadersListView
            ...>
    
  3. 最后,添加委托(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/

相关文章:

java - 将多个 JComponent 绘制到框架中

ios - UITableVIewController 在滚动条上显示文本

ios - 拉动刷新不会分离(不会停止刷新)-Objective-C

android - 下载 sqlite 文件并在我的 android 应用程序中使用它

android - 谷歌开发者控制台有错误,认为我有两个扩展文件,但应该是一个

python - 如何获取用套索选择器绘制的区域数组?

ios - 带有下拉刷新和锁定单元格的 UITableView,如 UltraVisual

java - Json数组和改造

android - 检索JSON中的特定字段

matlab - 避免中断 Matlab GUI 中的回调函数