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);
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,638评论 25 708
  • 昨天晚上回来已经十一点半左右了,想要更新文章已经来不及了,所以放在了今天早上更新,望大家不要见怪。 朋友之间还有一...
    MU心阅读 217评论 0 0
  • 2017.10.2 四人成行。滴滴到武汉站,印入眼帘的大烟囱。 某人习惯性的选择李先生餐厅,不过这次可没有红油腐...
    予信阅读 532评论 0 2
  • (九) 赞志新哥 一竿风波里,下水谋生存。船尖逐浪涌,网密鱼虾进。小个煮鲜汤,大头换余银。助兄书业读,手足似海深。...
    徐云喜阅读 519评论 2 6
  • Flowers are for spring, the Harvest Moon is for autumn. A...
    若无闲事阅读 231评论 0 0