我正在使用支持库中的SwipeRefreshListener
。我在我的AsyncTask
的onPreExecute
和onPostExecute
中调用了setRefresh
。然而,没有任何变化,也没有动画。我是否遗漏了什么?我是否需要设置某些参数以使其正常工作?
我正在使用支持库中的SwipeRefreshListener
。我在我的AsyncTask
的onPreExecute
和onPostExecute
中调用了setRefresh
。然而,没有任何变化,也没有动画。我是否遗漏了什么?我是否需要设置某些参数以使其正常工作?
这对我有用,更多信息请访问:http://antonioleiva.com/swiperefreshlayout/
SwipeRefreshLayout:布局您只需使用此新布局装饰可滑动的内容(可能是整个布局)。此视图必须是可滚动的,例如 ScrollView 或 ListView。以下是一个简单的示例:
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="@string/hello_world"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:gravity="center"/>
</ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
代码 我们只需要获取布局,指定一些颜色和监听器。刷新的监听器是一个后延迟处理程序。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
swipeLayout.setOnRefreshListener(this);
swipeLayout.setColorScheme(android.R.color.holo_blue_bright,
android.R.color.holo_green_light,
android.R.color.holo_orange_light,
android.R.color.holo_red_light);
}
@Override public void onRefresh() {
new Handler().postDelayed(new Runnable() {
@Override public void run() {
swipeLayout.setRefreshing(false);
}
}, 5000);
}
//请检查以下答案是否有帮助: //SwipeRefreshLayout setRefreshing()在初始化时没有显示指示器 //特别是这个
mSwipeRefreshLayout.post(new Runnable() {
@Override
public void run() {
mSwipeRefreshLayout.setRefreshing(true);
}
});