是否有可能将stickylistviewheader与crisbanes pulltorefresh合并?

shr*_*yas 4 user-interface android pull-to-refresh

我构建了一个应用程序,其中pulltorefresh和stickylistHeaders都需要.我已经在应用程序中实现了pulltorefresh但是无法使其与stickyListHeaders一起使用.是否有可能合并这两个库?或者有其他选择吗?任何想法?

Hel*_*den 7

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

  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;
        }
    }
    
    Run Code Online (Sandbox Code Playgroud)
  2. 在你的layout.xml替换

    <se.emilsjolander.stickylistheaders.StickyListHeadersListView
            ...>
    
    Run Code Online (Sandbox Code Playgroud)

    <com.yourapp.package.foo.PtrStickyListHeadersListView
            ...>
    
    Run Code Online (Sandbox Code Playgroud)
  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);
    
    Run Code Online (Sandbox Code Playgroud)