【问题标题】:Android using custom view PullToRefreshSwipeListViewAndroid 使用自定义视图 PullToRefreshSwipeListView
【发布时间】:2014-08-13 06:38:24
【问题描述】:

我正在尝试使用PullToRefreshSwipeListView 自定义视图类在列表视图中同时使用PullToRefreshSwipeListView 库。我是这样实现的:

首先我将 PullToRefresh 库导入到我的项目中,然后通过在其中创建一个 libs 文件夹,将 SwipeListView Jar File 添加到 PullToRefresh 库项目中。然后我在 PullToRefresh 库项目的 src 文件夹(com.handmark.pulltorefresh.library)中添加了 PullToRefreshSwipeListView 类。最后,我尝试将这个自定义类 PullToRefreshSwipeListView 实现到我的项目的 xml 中:

<com.handmark.pulltorefresh.library.PullToRefreshListView
    xmlns:swipe="http://schemas.android.com/apk/res-auto"
    xmlns:ptr="http://schemas.android.com/apk/res-auto"
    android:id="@+id/lv_Inbox"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:cacheColorHint="#00000000"
    android:divider="#19000000"
    android:dividerHeight="2dp"
    android:fadingEdge="none"
    android:fastScrollEnabled="false"
    android:footerDividersEnabled="false"
    android:headerDividersEnabled="false"
    android:scrollbars="none"
    android:smoothScrollbar="true"
    ptr:ptrAnimationStyle="flip" >

    <libs.swipelistview.SwipeListView
        android:id="@+id/users_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:cacheColorHint="#0000"
        android:clipToPadding="false"
        android:divider="@null"
        android:dividerHeight="0px"
        android:fadingEdge="none"
        android:scrollbarStyle="outsideOverlay"
        swipe:swipeActionLeft="reveal" />
</com.handmark.pulltorefresh.library.PullToRefreshListView>

但我在 xml 中遇到错误:

  • 错误:在包中找不到属性“swipeActionLeft”的资源标识符
  • 错误:在包中找不到属性“swipeActionLeft”的资源标识符
  • 错误:在包中找不到属性“swipeMode”的资源标识符

它没有获得任何滑动属性,但如果我删除滑动属性。它仅适用于 PullToRefresh。我正在关注this 链接来实现它。任何解决方案/意见将不胜感激。

【问题讨论】:

标签: android android-listview pull-to-refresh swipeview


【解决方案1】:

您为什么要尝试将 PullToRefresh 合并到 SwipeListView 库中?我已经将 PullToRefresh 与 SwipeListView 一起使用,没有任何问题(只是使用 gradle 而不是 JAR 导入)。

您收到这些错误是因为您没有从 SwipeListView 库中的 res/values 复制 swipelistview__attrs.xml (this file)

【讨论】:

  • 我正在使用 Eclipse 而不是 Android Studio 无法使用 gradle。这就是为什么我使用 swipelistview 的 jar 文件
  • 您是否尝试将 swipelistview__attrs.xml 文件复制到 project/pulltorefresh 中?
  • 您如何将 PullToRefresh 与 SwipeListView 一起使用?你可以在这里发布一些代码。我认为需要在 xml 文件中为 PullToRefresh 和 SwipeListView 库添加自定义 ListView 项。 PullToRefresh 像
  • 好的,我确实根据您提供的链接更改了我的代码。我已经在我的问题描述中编辑了代码。我现在已经分离了两个库并分别添加到我的项目中。现在我在 XML 中没有收到任何错误。但是如何在 Java 代码中同时使用它们呢?因为 PullToRefresh 和 SwipeRefresh 都在代码中返回 listview 对象。如何使用它们。我应该分别制作两个对象,但我会有两个列表视图吗?请告诉我您在代码中的表现如何?谢谢
  • PullToRefreshLayout 不是 ListView。您必须使您的 Activity 或 Fragment 实现 OnRefreshListener。在 onCreateView 或 OnCreate 添加这些行: mPullToRefreshLayout = (PullToRefreshLayout) view.findViewById(R.id.pull_refresh); ActionBarPullToRefresh.from(getActivity()).allChildrenArePullable().listener(this).setup(mPullToRefreshLayout);
【解决方案2】:
better you go with 
swiperefresh layout

https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html

【讨论】:

  • 当用户像 Facebook Android 应用一样 pulltorefresh 时,我想要翻转效果。 SwipeRefreshLayout 在 pulltorefresh 时提供类似 Gmail 的效果。此外 SwipeRefreshLayout 仅适用于垂直滑动手势。我正在尝试在列表项上实现水平滑动。所以即使我实现 SwipeRefreshLayout 我也必须实现 SwipeListView 库。问题仍然存在
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-20
  • 1970-01-01
  • 1970-01-01
  • 2019-02-01
  • 1970-01-01
相关资源
最近更新 更多