问题描述
我正在使用支持库中的SwipeRefreshListener
.我正在从AsyncTask
的onPreExecute
和onPostExecute
调用setRefresh
.但是,没有任何变化,没有动画.有什么我想念的吗?是否需要设置某些设置参数才能使其正常工作?
I'm using SwipeRefreshListener
from the support libraries. I am calling setRefresh
from onPreExecute
and onPostExecute
of my AsyncTask
. However, nothing changes, there is no animation. Is there something that I'm missing? Are there certain setup parameters I need to set in order for it to work properly?
推荐答案
这对我有用,请在此处查看更多信息: http://antonioleiva. com/swiperefreshlayout/
This has worked for me, see more here: http://antonioleiva.com/swiperefreshlayout/
SwipeRefreshLayout:布局您只需使用此新布局来装饰可滑动内容(可能是整个布局).该视图必须是可滚动的,例如ScrollView或ListView.举一个简单的例子:
SwipeRefreshLayout: The layoutyou only need to decorate the swipable content (probable the whole layout) with this new layout. This view must be scrollable, such a ScrollView or a ListView. As a simple example:
<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>
代码我们只需要获取布局,并分配一些颜色和侦听器即可.令人耳目一新的侦听器是一个延迟发布的处理程序.
The codeWe just need to get the layout, and assign some colours and the listener. The refreshing listener is a post delayed handler.
@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不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!