Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

作者:常见问题 #71

Open
scwang90 opened this issue Jul 20, 2017 · 17 comments
Open

作者:常见问题 #71

scwang90 opened this issue Jul 20, 2017 · 17 comments

Comments

@scwang90
Copy link
Owner

scwang90 commented Jul 20, 2017

本 Issue 仅限作者维护,其他人不要回复,这里不是提问的板块

- 常见问题文档版

//禁止上拉加载:
refreshLayout.setEnableLoadmore(false); 
//使上拉加载具有弹性效果:
refreshLayout.setEnableAutoLoadmore(false); 
//禁止越界拖动:
refreshLayout.setEnableOverScrollDrag(false);
@scwang90
Copy link
Owner Author

scwang90 commented Jul 20, 2017

不能上拉加载更多?

尝试:

<SmartRefreshLayout
    app:srlEnableLoadmore="true"
    app:srlEnableLoadmoreWhenContentNotFull="true">
</SmartRefreshLayout>

或者:

refreshlayout.setEnableLoadmore(true);
refreshlayout.setLoadmoreFinish(false);
refreshlayout.setEnableLoadmoreWhenContentNotFull(true);//内容不满屏幕的时候也开启加载更多

如果还是不行请考虑使用列表的 Adapter 是否隐藏了某个item或者把某个item高度设置为0

@scwang90
Copy link
Owner Author

scwang90 commented Jul 20, 2017

如何修改刷新文字?

SmartRefresh的经典文字自带了国际化(中/英),如需自定义文字显示,可以通过以下两种方法设置:

代码设置(APP在运行是,更改系统语言,本方法无效)

ClassicsHeader 和 ClassicsFooter 的描述文字是可以修改的,不要看错成了常量哦~

public class App extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        ClassicsHeader.REFRESH_HEADER_PULLING = getString(R.string.header_pulling);//"下拉可以刷新";
        ClassicsHeader.REFRESH_HEADER_REFRESHING = getString(R.string.header_refreshing);//"正在刷新...";
        ClassicsHeader.REFRESH_HEADER_LOADING = getString(R.string.header_loading);//"正在加载...";
        ClassicsHeader.REFRESH_HEADER_RELEASE = getString(R.string.header_release);//"释放立即刷新";
        ClassicsHeader.REFRESH_HEADER_FINISH = getString(R.string.header_finish);//"刷新完成";
        ClassicsHeader.REFRESH_HEADER_FAILED = getString(R.string.header_failed);//"刷新失败";
        ClassicsHeader.REFRESH_HEADER_UPDATE = getString(R.string.header_update);//"上次更新 M-d HH:mm";
        ClassicsHeader.REFRESH_HEADER_UPDATE = getString(R.string.header_update);//"'Last update' M-d HH:mm";
        ClassicsHeader.REFRESH_HEADER_SECONDARY = getString(R.string.header_secondary);//"释放进入二楼"

        ClassicsFooter.REFRESH_FOOTER_PULLING = getString(R.string.footer_pulling);//"上拉加载更多";
        ClassicsFooter.REFRESH_FOOTER_RELEASE = getString(R.string.footer_release);//"释放立即加载";
        ClassicsFooter.REFRESH_FOOTER_LOADING = getString(R.string.footer_loading);//"正在刷新...";
        ClassicsFooter.REFRESH_FOOTER_REFRESHING = getString(R.string.footer_refreshing);//"正在加载...";
        ClassicsFooter.REFRESH_FOOTER_FINISH = getString(R.string.footer_finish);//"加载完成";
        ClassicsFooter.REFRESH_FOOTER_FAILED = getString(R.string.footer_failed);//"加载失败";
        ClassicsFooter.REFRESH_FOOTER_NOTHING = getString(R.string.footer_nothing);//"全部加载完成";
    }
}

资源覆盖(1.1.0 以上版本)

<resources>
    <string name="srl_header_pulling">下拉可以刷新</string>
    <string name="srl_header_refreshing">正在刷新…</string>
    <string name="srl_header_loading">正在加载…</string>
    <string name="srl_header_release">释放立即刷新</string>
    <string name="srl_header_finish">刷新完成</string>
    <string name="srl_header_failed">刷新失败</string>
    <string name="srl_header_update">上次更新 M-d HH:mm</string>
    <string name="srl_header_secondary">释放进入二楼</string>

    <string name="srl_footer_pulling">上拉加载更多</string>
    <string name="srl_footer_release">释放立即加载</string>
    <string name="srl_footer_loading">正在加载…</string>
    <string name="srl_footer_refreshing">正在刷新…</string>
    <string name="srl_footer_finish">加载完成</string>
    <string name="srl_footer_failed">加载失败</string>
    <string name="srl_footer_nothing">没有更多数据了</string>
</resources>

XML直接指定(1.1.0 最新版)

    <com.scwang.smartrefresh.layout.header.ClassicsHeader
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:srlTextPulling="@string/srl_header_pulling"
        app:srlTextLoading="@string/srl_header_loading"
        app:srlTextRelease="@string/srl_header_release"
        app:srlTextFinish="@string/srl_header_finish"
        app:srlTextFailed="@string/srl_header_failed"
        app:srlTextUpdate="@string/srl_header_update"
        app:srlTextSecondary="@string/srl_header_secondary"
        app:srlTextRefreshing="@string/srl_header_refreshing"/>

    <com.scwang.smartrefresh.layout.header.ClassicsFooter
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:srlTextPulling="@string/srl_footer_pulling"
        app:srlTextRelease="@string/srl_footer_release"
        app:srlTextLoading="@string/srl_footer_loading"
        app:srlTextRefreshing="@string/srl_footer_refreshing"
        app:srlTextFinish="@string/srl_footer_finish"
        app:srlTextFailed="@string/srl_footer_failed"
        app:srlTextNothing="@string/srl_footer_nothing"/>

@scwang90 scwang90 changed the title 提问,请先看这个! 作者:提问,请先看这个! Jul 20, 2017
@scwang90 scwang90 changed the title 作者:提问,请先看这个! 作者:常见问题荟萃 Jul 20, 2017
@scwang90
Copy link
Owner Author

scwang90 commented Jul 20, 2017

触发下拉刷新的距离

本库触发下拉刷新的距离就是 Header 的高度乘以比率:HeaderHeight*HeaderTriggerRate,下拉的距离超过这个值释放时就可以触发刷新事件,否则回弹到原始状态。

HeaderTriggerRate 默认是 1,改成0.5,那么再下拉到一半的时候就可以刷新了
改变这个距离就是 setHeaderHeight setHeaderHeightPx
footer 类推

相关方法

name format description
setHeaderHeight dimension Header的标准高度(px/dp 两个版本)
setFooterHeight dimension Footer的标准高度(px/dp 两个版本)
setHeaderTriggerRate float Header触发刷新距离 与 HeaderHeight 的比率(默认1)
setFooterTriggerRate float Footer触发加载距离 与 FooterHeight 的比率(默认1)

相关属性

name format description
srlHeaderHeight dimension Header的标准高度(dp)
srlFooterHeight dimension Footer的标准高度(dp)
srlHeaderTriggerRate float Header触发刷新距离 与 HeaderHeight 的比率(默认1)
srlFooterTriggerRate float Footer触发加载距离 与 FooterHeight 的比率(默认1)

@scwang90
Copy link
Owner Author

scwang90 commented Jul 20, 2017

显示没有更多数据,并不再触发加载更事件

//新版本
refreshlayout.finishLoadMoreWithNoMoreData();

//老版本
refreshlayout.finishLoadmore();
refreshlayout.setLoadmoreFinish(true);//1.0.4 及一下版本
refreshlayout.setNoMoreData(true);//1.0.5 以上

@scwang90
Copy link
Owner Author

scwang90 commented Jul 20, 2017

加载更多一直显示?不能触发下拉刷新?

//尝试在 setLoadmoreFinish 之前加上 finishLoadmore
refreshlayout.finishLoadmore();
refreshlayout.setLoadmoreFinish(false);//1.0.4 及一下版本
refreshlayout.setNoMoreData(false);//1.0.5 以上

@scwang90
Copy link
Owner Author

自定义Header和Footer

简单自定义Header和Footer
常规自定义Header和Footer

@scwang90
Copy link
Owner Author

scwang90 commented Jul 23, 2017

全局设置 除Header,Footer 之外的基本参数?

public class App extends Application {

    static {
        SmartRefreshLayout.setDefaultRefreshHeaderCreator(new DefaultRefreshHeaderCreator() {
            @NonNull
            @Override
            public RefreshHeader createRefreshHeader(Context context, RefreshLayout layout) {
                //开始设置全局的基本参数
                layout.setReboundDuration(1000);
                layout.setReboundInterpolator(new DropBounceInterpolator());
                layout.setFooterHeight(100);
                layout.setDisableContentWhenLoading(false);
                //更多的 set 方法
                return new ClassicsHeader(context).setSpinnerStyle(SpinnerStyle.Translate);
            }
        });
    }
}

@scwang90
Copy link
Owner Author

没有上拉,快速滚动列表,Footer自己冒上来了?

这个功能是本刷新库的特色功能:在列表滚动到底部时自动加载更多。
如果不想要这个功能,是可以关闭的:

refreshlayout.setEnableAutoLoadmore(false);

@scwang90
Copy link
Owner Author

scwang90 commented Jul 24, 2017

还没调用 finishRefresh ,刷新就自动结束了?

解决办法:setRefreshListener

refreshLayout.setRefreshListener(listener);

实际项目中都会设置监听器的,所以不设置的都是demo,为了demo方便就默认3秒之后关闭了,如果一直不关闭,体验不好

@scwang90
Copy link
Owner Author

scwang90 commented Jul 24, 2017

添加固定的头布局

本库支持添加固定的头布局,参考 Demo-实战-微博列表

image

注意:是固定的头布局,如果是想添加可以滚动的头布局,请使用开源的Adapter实现

Repository owner deleted a comment from dengxiaosong Aug 24, 2017
Repository owner deleted a comment from quanqiuheike Aug 30, 2017
Repository owner deleted a comment from yswserven Sep 16, 2017
Repository owner deleted a comment from Juny4541 Sep 22, 2017
@scwang90
Copy link
Owner Author

AndroidStudio 不能预览

这个问题并不会影响运行效果,如果无法忍受预览失效
请加上

compile 'com.android.support:design:25.3.1'

Repository owner deleted a comment from LiNengYu Sep 30, 2017
Repository owner deleted a comment from DaisyJin1 Oct 11, 2017
@scwang90 scwang90 changed the title 作者:常见问题荟萃 作者:常见问题 Oct 27, 2017
Repository owner deleted a comment from kimonic Oct 28, 2017
Repository owner deleted a comment from xpengb Nov 16, 2017
Repository owner deleted a comment from kazarf007 Dec 21, 2017
Repository owner deleted a comment from zhiyongshuangquan Jan 5, 2018
Repository owner deleted a comment from huangqiankun123 Jan 15, 2018
@scwang90 scwang90 self-assigned this Jan 25, 2018
Repository owner deleted a comment from rmtic Feb 1, 2018
@scwang90
Copy link
Owner Author

scwang90 commented Mar 22, 2018

获取当前状态?isRefreshing(),isLoading() 不见了?

版本的迭代,刷新的状态越来越多,仅仅由 isRefreshing(),isLoading() 已经无法满足要求,再1.0.5版本之后本库直接将 内部 State 开放出来,并标记 isRefreshing(),isLoading() 过期,鼓励大家使用 getState 来代替。getState 比 前两个方法更有用,具体参考下面代码。

    refreshLayout.getState() == RefreshState.None //空闲状态
    refreshLayout.getState() == RefreshState.Loading//代替 isLoading
    refreshLayout.getState() == RefreshState.Refreshing//代替 isRefreshing

    refreshLayout.getState().isDragging //判断是否正在拖拽刷新控件(非拖拽列表)
    refreshLayout.getState().isFinishing //判断动画是否正在结束
    refreshLayout.getState().isHeader //判断当前是否处于 Header 的一系列状态中
    refreshLayout.getState().isFooter //判断当前是否处于 Footer 的一系列状态中
    refreshLayout.getState().isOpening // 等同于 isLoading || isRefreshing

Repository owner deleted a comment from lvzhiwei0221 May 6, 2018
Repository owner deleted a comment from huafresh Aug 19, 2018
Repository owner deleted a comment from Cuiernao Oct 12, 2018
@scwang90
Copy link
Owner Author

scwang90 commented Dec 15, 2018

不显示“加载完成”和“刷新完成”,直接因此 Header或者Footer。

Smart 可以修改 “加载完成”和“刷新完成” 的显示时间,所以想不现实它们,直接把显示时间设置为0即可。

header.setFinishDuration(0);//设置Footer 的 “刷新完成” 显示时间为0
footer.setFinishDuration(0);//设置Footer 的 “加载完成” 显示时间为0

@scwang90 scwang90 pinned this issue Dec 26, 2018
@scwang90
Copy link
Owner Author

scwang90 commented Jan 21, 2019

与 RecyclerView,ListVIew,ScrollView,NestScrollView,滚动冲突

  1. 如果是 RecyclerView 和 NestScrollView 先尝试打开 Smart 的嵌套滚动功能
  2. 如果是 ListVIew,ScrollView,可以尝试 同时打开 ScrollView,ScrollView,Smart 的嵌套滚动功能
  3. 如果 1,2 都无效,这需要自定义滚动边界自己实现 canRefresh 和 canLoadmore,自己用代码告诉Smart 什么时候可以 刷新,什么时候可以加载
refreshLayout.setScrollBoundaryDecider(new ScrollBoundaryDeciderAdapter(){
    @Override
    public boolean canRefresh(View content) {
        return /*自己实现是否可以刷新,通过返回 true false*///super.canRefresh(content);
    }
});

@minorlai
Copy link

多语言切换只能支持中英文?别的国家语言只能clone下来添加才能支持吗?

@121104115wyb
Copy link

AndroidStudio 不能预览

这个问题并不会影响运行效果,如果无法忍受预览失效 请加上

compile 'com.android.support:design:25.3.1'

加上这个还是无法预览,求解决?只要使用了ConstraintLayout 基本都无法预览

@rmtic
Copy link

rmtic commented Aug 1, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants