如何用android listview制作刷新动画?

时间:2015-08-14 01:31:44

标签: android listview animation

我有一个我的Android应用程序的列表视图,我想在列表视图的顶部制作一个动画,当用户滚动像一个用于Instagram或Twitter应用程序的动画。我该怎么做呢当用户滚动并且我正在考虑使用frameanimation进行实际动画时,是否有一个方法被调用。

1 个答案:

答案 0 :(得分:2)

您可以在xml文件中添加滑动刷新布局:

 <android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/favs_refresher"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1">
    <ListView
        android:id="@+id/favs_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"/>
</android.support.v4.widget.SwipeRefreshLayout>

然后关于你的活动:

    swipeRefresher = (SwipeRefreshLayout)findViewById(R.id.favs_refresher);
    swipeRefresher.setOnRefreshListener(this);

确保您的活动实施SwipeRefreshLayout.OnRefreshListener

然后您可以使用onRefresh()方法:

@Override
public void onRefresh() {
    //do something
}