【发布时间】:2014-07-20 21:43:01
【问题描述】:
我正在使用支持库中的SwipeRefreshListener。我从onPreExecute 和onPostExecute 的AsyncTask 打电话给setRefresh。但是,没有任何变化,没有动画。有什么我想念的吗?是否需要设置某些设置参数才能使其正常工作?
【问题讨论】:
标签: android android-widget android-support-library
我正在使用支持库中的SwipeRefreshListener。我从onPreExecute 和onPostExecute 的AsyncTask 打电话给setRefresh。但是,没有任何变化,没有动画。有什么我想念的吗?是否需要设置某些设置参数才能使其正常工作?
【问题讨论】:
标签: android android-widget android-support-library
这对我有用,在此处查看更多信息: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() not showing indicator initially //尤其是这个
mSwipeRefreshLayout.post(new Runnable() {
@Override
public void run() {
mSwipeRefreshLayout.setRefreshing(true);
}
});
【讨论】: