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

2024-02-24

我构建了一个应用程序,其中需要 pulltorefresh 和 StickylistHeaders。我已经在应用程序中实现了 pulltorefresh,但无法使其与 StickyListHeaders 一起使用。是否可以合并这两个库? 或者有什么替代方案吗?有什么想法吗?


更新这两个库后,我的实现也被破坏了。这是我的快速解决让它再次发挥作用。欢迎任何建议和改进!

  1. 创建一个新类并扩展 SticklistListHeadersListView 并实现 ActionBar-PullToRefresh 中的 ViewDelegate 接口:

    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 replace

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

    with

    <com.yourapp.package.foo.PtrStickyListHeadersListView
            ...>
    
  3. 最后,添加委托:(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);
    
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

是否可以将 stickylistviewheader 与 crisbanes pulltorefresh 合并? 的相关文章

随机推荐