【问题标题】:is it possible to merge stickylistviewheader with crisbanes pulltorefresh?是否可以将stickylistviewheader 与crisbanes pulltorefresh 合并?
【发布时间】:2013-11-22 10:48:51
【问题描述】:

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

【问题讨论】:

    标签: android user-interface pull-to-refresh


    【解决方案1】:

    在更新两个库后,我的实现也被破坏了。这是我的快速修复,让它再次工作。 欢迎提出任何建议和改进!

    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 替换

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

      <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);
      

    【讨论】:

      【解决方案2】:

      与 Helden 的回答类似,您也可以使用匿名内部类实现此目的,而无需扩展 StickyListHeadersListView

          myList = (StickyListHeadersListView) v.findViewById(R.id.your_list_id);
          ActionBarPullToRefresh.from(getActivity())
                  .allChildrenArePullable()
                  .listener(this)
                  .useViewDelegate(StickyListHeadersListView.class, new ViewDelegate() {
                      @Override
                      public boolean isReadyForPull(View view, float v, float v2) {
                          return ... //check if list is scrolled to the top or not
                      }
                  })
                  .setup(mPullToRefreshLayout);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-11-08
        • 1970-01-01
        • 1970-01-01
        • 2021-01-09
        • 2017-03-01
        • 2022-08-15
        • 2019-03-06
        相关资源
        最近更新 更多