Android 滑动布局:滑动进度动画

Android 滑动布局:滑动进度动画,android,listview,android-animation,swiperefreshlayout,Android,Listview,Android Animation,Swiperefreshlayout,我是android新手,我正在谷歌网站上探索示例代码。我当前使用的代码是SwipeRefreshLayout: 在代码中,我们看到正在为listview执行SwipeRefreshLayout,换句话说,如果向下拖动列表视图,将触发该方法,listview将刷新自身 <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"

我是android新手,我正在谷歌网站上探索示例代码。我当前使用的代码是SwipeRefreshLayout:

在代码中,我们看到正在为listview执行SwipeRefreshLayout,换句话说,如果向下拖动列表视图,将触发该方法,listview将刷新自身

<android.support.v4.widget.SwipeRefreshLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/swiperefresh"
      android:layout_width="match_parent"
      android:layout_height="match_parent">

    <ListView
          android:id="@android:id/list"
          android:layout_width="match_parent"
          android:layout_height="match_parent" />

</android.support.v4.widget.SwipeRefreshLayout>

并没有说什么。

您不能更改动画

SwipeRefreshLayout
中,您不能定制太多;我相信这是谷歌试图让开发者坚持共同的模式。您可以设置动画的四种颜色的样式,使用
setColorScheme()
指定


SwipeRefreshLayout
会在顶部为您显示预定义的动画。这可能是当
canChildScrollUp()
返回false且用户“下拉”时,或者当您设置
setRefreshing(true)
时。使用
设置刷新(false)
关闭动画。将逻辑放在侦听器的方法
onRefreshing()
中。如果在
SwiperFreshLayout
中放置了非
ListView
的内容,请覆盖
canChildScrollUp()
。您应该很乐意从这里开始。

虽然您无法更改它,但您仍然可以隐藏它,然后在触发后显示您自己的:-)

注:

  • 在eclipse中,您必须添加@SuppressLint(“ResourceAsColor”)来编译它

  • 您仍然需要在适当的时间点调用setRefresh(false),否则onRefresh不会再次触发


谢谢。我想你是对的,除了设置进度条的颜色之外,没有什么可以定制的。您还知道SwipeRefreshLayout类是否会自动为listview操作notifyDataChanged()方法吗?listview在用户通过mListAdapter.add(cheese)方法下拉3秒后自动刷新,但是,从未调用notifyDataChanged()方法来通知listview其数据的更改。不,它没有。您可以检查自己的代码,在sdk目录中搜索
SwipeRefreshLayout.java
。您需要安装支持v4库(版本19.1.0)的最新版本的源代码,因此我猜当数据添加到适配器时,listview会自动刷新:mListAdapter.add(cheese)?mListAdapter有什么类型?无论如何,我认为你最好还是完全问一个新问题。setProgressBackgroundColor(android.R.color.transparent)被弃用了。使用swiperefresh.setProgressBackgroundColorSchemeResource(android.R.color.transparent);相反,这已经不起作用了。然而,我发现将视图的alpha更新为0就可以了。
SwipeRefreshLayout swiperefresh = (SwipeRefreshLayout)root.findViewById(R.id.swiperefresh);
swiperefresh.setOnRefreshListener(this);
swiperefresh.setColorSchemeColors(0,0,0,0);
swiperefresh.setProgressBackgroundColor(android.R.color.transparent);