SwipeRefreshLayout.setRefreshing(true)不显示的解决办法

的app有一个切换界面也会出现SwipeRefreshLayout进度圈的功能,本来以为直接setRefreshing(true);就能解决了,没想到不管用,百度了一下网上提供了很多种解决方法,主要对网上的几种方法进行总结一个可以进页面自动显示刷新效果的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);

你可能感兴趣的:(SwipeRefreshLayout.setRefreshing(true)不显示的解决办法)