No adapter attached; skipping layout 原因、解决办法
2017-12-21 15:50
417 查看
当问题出现的时候不光要解决还要知道为什么
众所周知,RecyclerView的出现不光可以代替ListView,也可以代替GridView,所以啊大胸弟,你在用的时候要告诉系统你要代替的是哪个啊,就是所谓的初始化配置,不配置就会警告报错、不显示数据
分割线可以不设置,动画也可以不设置,但是LayoutManager
必须设置。
随意示范一下LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false); mRecyclerView.setLayoutManager(linearLayoutManager);
上面用的是LinearLayoutManager的第二个构造方法,必要的参数都有了,当然也可以用第一个构造,然后再设置orientation,都一样,我喜欢一次性写完,贴一下这个构造的代码:
/** * @param context Current context, will be used to access resources. * @param orientation Layout orientation. Should be {@link #HORIZONTAL} or {@link * #VERTICAL}. * @param reverseLayout When set to true, layouts from end to start. */ public LinearLayoutManager(Context context, int orientation, boolean reverseLayout) { setOrientation(orientation); setReverseLayout(reverseLayout); setAutoMeasureEnabled(true); }
几种LayoutManager
LinearLayoutManager 线性布局管理器
GridLayoutManager 表格布局管理器
StaggeredGridLayoutManager 瀑布流布局管理器
相关文章推荐
- RecyclerView 提示No adapter attached; skipping layout 解决方法
- RecyclerView 提示No adapter attached; skipping layout 解决方法
- No adapter attached; skipping layout解决方法
- make: *** No rule to make target 错误原因、分析和解决办法
- Nested Loops join时显示no join predicate原因分析以及解决办法
- Python+Selenium定位不到元素常见原因及解决办法(报:NoSuchElementException)
- FragmentStatePagerAdapter第二次加载时不能显示其界面的原因及解决办法
- 调试出现"no matching symbolic information found"原因以及解决办法
- modulenotfounderror: no module 或modulenotfounderror: no module named 'matplotlib._path' 原因详解及解决办法
- Uncaught Error: USERKEY_PLAT_NOMATCH 的原因和解决办法
- linux下system函数错误返回-1,错误原因NO child processes的解决办法
- 使用RecyclerView时出现:RecyclerView: No adapter attached; skipping layout
- Python+Selenium定位不到元素常见原因及解决办法(报:NoSuchElementException)
- ConfigParser.NoSectionError: No section: 'formatters'原因及解决办法
- .Net数据库开发,关于adapter.update()无效的原因及解决办法
- ConfigParser.NoSectionError: No section: 'formatters'原因及解决办法
- 关于shell脚本提示No such file or directory的解决办法和原因
- android.database.sqlite.SQLiteException: no such table出现原因与解决办法
- ConfigParser.NoSectionError: No section: 'formatters'原因及解决办法
- android.database.sqlite.SQLiteException: no such table错误出现的原因及解决办法