簡書的app有一個切換界面也會出現(xiàn)SwipeRefreshLayout進度圈的功能奈懒,本來以為直接setRefreshing(true)去团;就能解決了茁影,沒想到不管用,百度了一下網(wǎng)上提供了很多種解決方法斯嚎,主要對網(wǎng)上的幾種方法進行總結一個可以進頁面自動顯示刷新效果的SwipeRefreshLayout,這里是通過自定義一個繼承SwipeRefreshLayout的 類挨厚,加上一個autoRefresh() 的刷新方法堡僻,調用autoRefresh() 就能刷新。:
public class AutoSwipeRefreshLayout extends SwipeRefreshLayout {
public AutoSwipeRefreshLayout(Context context) {
super(context);
}
public AutoSwipeRefreshLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
/**
* 自動刷新
*/
public void autoRefresh() {
try {
Field mCircleView = SwipeRefreshLayout.class.getDeclaredField(mCircleView);
mCircleView.setAccessible(true);
View progress = (View) mCircleView.get(this);
progress.setVisibility(VISIBLE);
Method setRefreshing = SwipeRefreshLayout.class.getDeclaredMethod(setRefreshing, boolean.class, boolean.class);
setRefreshing.setAccessible(true);
setRefreshing.invoke(this, true, true);
} catch (Exception e) {
e.printStackTrace();
}
}
}
SwipeRefreshLayout.setRefreshing(true)不起作用解決辦法
通過:
sw = (SwipeRefreshLayout) getActivity().findViewById(R.id.indext_swp);
sw.setColorScheme(R.color.main_color, R.color.red, R.color.green);
sw.post(new Runnable() {
@Override
public void run() {
sw.setRefreshing(true);
}
});
或者遇見SwipeRefreshLayout一點點問題疫剃,設置setRefreshing(true)沒效果設置一個位移量再setRefreshing(true)钉疫;
refresh.setProgressViewOffset(false, 0, CommonUtil.dip2px(context, 24));
refresh.setRefreshing(true);