Comments (6)
recyclerview父层是 swipeRefreshLayout
from loadsir.
@duweigang 请参考我的Demo:LoadSirBestPractice,和你描述的差不多场景。如果还有疑问我们再详细谈论。
from loadsir.
已经找到原因:关于swipeRefreshLayout嵌套recyclerview的问题时,loadLayout宽高为0的原因。
原因是我在register(recyclerview)【之前】,先行调用了swipeRefreshLayout.setColorSchemeColors(Color.parseColor("#893712"));
这样一段代码。
而在如上方法的源码调用了如下方法:
private void ensureTarget() {
// Don't bother getting the parent height if the parent hasn't been laid
// out yet.
if (mTarget == null) {
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
if (!child.equals(mCircleView)) {
mTarget = child;
break;
}
}
}
}
其中主要是确定了mTarget指向了recyclerview。
之后我调用register(recyclerview),然后按照View绘制流程,执行到SwipeRefreshLayout.onMeasure()
中有这么一段代码:
mTarget.measure(MeasureSpec.makeMeasureSpec(
getMeasuredWidth() - getPaddingLeft() - getPaddingRight(),
MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(
getMeasuredHeight() - getPaddingTop() - getPaddingBottom(), MeasureSpec.EXACTLY));
因为此时的target是recyclerview,会计算recyclerview的宽高,但是因为SwipeRefreshLayout认为mTarget才是他的child,所以,之后在register了recyclerview之后,swipeRefreshLayout的mTarget按照正常逻辑应该是指向loadlayout,但是实际情况是继续指向recyclerview,整个过程loadlayout都没有执行过他自己的measure方法,所以宽高才是0。
当然如果不调用setColorSchemeColors
这个方法,其实register和view的初始化调用顺序怎么写都没事,因为在绘制时,register之后是会指向正确的loadlayout。这里之所以会有问题,也是和SwipeRefreshLayout这个控件的measure方法实现有关。
可能有分析不到位的地方。。。(说这些是希望后来者别被这个调用顺序坑到),感觉作者可以加些说明关于调用的顺序方面。
from loadsir.
@duweigang 感谢你提供详细原因:smiley: ,我会将你的宝贵经验放入FAQ中。
from loadsir.
@KingJA 不客气,感谢作者对开源做出的贡献
from loadsir.
@duweigang Thanks a lot. 欣慰.
from loadsir.
Related Issues (20)
- 项目还维护吗? HOT 2
- 注册view布局时会出现问题
- 能够加在切换界面状态的时候加入动画 能够淡入淡出 HOT 1
- 在使用转换器回调的时候如何动态修改错误页面的提示文字 HOT 2
- 有没有人遇到当数据很快获取到时,不能显示成功布局,还是加载布局的情况? HOT 6
- 承载各个fragment的容器如果是FragmentContainerView或者Fragment,在调用register注册时会crash HOT 1
- DefaultCallback 调用时机有问题 HOT 3
- 什么时候增加viewbinding 支持?
- 某个页面自定义loadsir不会继承默认全局里面的callback? HOT 2
- loadIsr无法取消
- jcent仓库要过期了 不更新一下吗
- 用loadSir绑定SmartRefreshLayout中的RecyclerView 直接就空白视图 什么都不展示 HOT 3
- onReloadEvent 事件重写 点击特定view的事件 第一次无响应 ,第二次才触发 点击事件 HOT 3
- 为什么不提供一个unregister的方法呢 HOT 1
- 请问什么时候迁移到maven-central呢? HOT 4
- 希望添加获取当前显示的 View
- 建议添加View显示时的动画
- 承载各个fragment的容器如果是FragmentContainerView或者Fragment,在调用register注册时会crash HOT 2
- 一个界面能使用多个load吗?两个RV,会造成滑动,好像也没显示loading
- 是不是已经不更新了 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from loadsir.