使用的是AS 2.1.1版本。没有升级的原因的是怕比较坑。
但是... 还是被坑了。
项目中要使用嵌套滑动的效果.很多个人详情页(知乎,微博等等)目前主流都需要这种效果..
使用Android Design Support 库中 CoordinatorLayout 配合collapsingtoolbarlayout appbarlayout配合可以实现。
自己实现NestedScrollingParent NestedScrollingChild 接口也可以实现。
但是我们项目中使用的是自定义的Listview,而Listview并没有实现NestedScrollingChild ,只是在API>=21的时候 才有enable nestedScrolling的属性。
评估了一下,切换成RecyclerView代价太大,大量的adpater,自定义下拉刷新,上拉加载 的效果都需要重新写。
自定义listview不能换。
毫无疑问,要支持listview,得自己动手。
项目紧,时间急,想赶紧上车,没太多时间研究Nestedscroll如何实现,就各种找了能支持Listview 嵌套滑动的开源控件。
各种调试了大半天,头晕脑胀之后... 开始掉坑里了...
使用了https://github.com/ta893115871/StickyNavLayout 来实现嵌套滑动。 各种布局设置好后。run~~~ 很自信的点开activity
Caused by: java.lang.RuntimeException: Binary XML file line #20: You must supply a layout_width attribute.
at android.app.Activity.setContentView(Activity.java:2184)
OK。。20行。 少一个layout_width
我瞟了一眼。 反复看了3遍, xml 20 行,
android:layout_width="match_parent" android:layout_height="200dp" android:background="#fee" android:orientation="vertical"
妥妥的没问题。 instant run的问题吧。我clean 。继续run 点开activity。
Caused by: java.lang.RuntimeException: Binary XML file line #20: You must supply a layout_width attribute.
at android.app.Activity.setContentView(Activity.java:2184)
又给我蹦了。
Interesting.我调整了布局,让20行那一片区域都没有布局代码,并且反复检查了一般每一个Layout和view 。都有layout_width、
再clean ,再run。
Caused by: java.lang.RuntimeException: Binary XML file line #20: You must supply a layout_width attribute.
at android.app.Activity.setContentView(Activity.java:2184)
厉害了。我20行都没有代码了,还给我报20行缺少width属性。我怀疑是不是代码里面 哪里把某个view取出来,然后把layout_width置空了?? Ok 把代码都注释了。
Caused by: java.lang.RuntimeException: Binary XML file line #20: You must supply a layout_width attribute.
at android.app.Activity.setContentView(Activity.java:2184)
可以的。 那只能一个一个注释布局了。 布局注释到只剩根布局的时候,错误终于消除了。
有点头晕。 这点小问题,折腾2小时.. 下班回去 睡了一觉。。
第二天早上。
无意间点开布局其中的一个include文件
竟然是这样的。刚好是第20行。
Rendering Problems NOTE: One or more layouts are missing the layout_width or layout_height attributes. These are required in most layouts.
我去.这样androidstudio 在文件名这都不给我来个红线。一样可以build 可以run 。
太牛逼了。
总结一下Caused by: java.lang.RuntimeException: Binary XML file line #20: You must supply a layout_width attribute.
报20行错误,这个20行不一定是当前布局文件下的,也可能是任何Include的布局文件下的第20行。。。
这个道理早点知道,也就知道早点去各个Include 布局里面的第20行找了。
浪费2个多小时。。