SwipeToLoadLayout 使用时需要注意的事项. 作为下拉刷新,和上拉加载的三方jar包 是挺好用的.今天我使用时,发现有个需要注意的地方
下面是在布局中使用SwipeToLoadLayout,
<com.aspsine.swipetoloadlayout.SwipeToLoadLayout android:id="@+id/swipeToLoadLayoutAdd" android:layout_width="match_parent" android:layout_height="match_parent" > <include android:id="@id/swipe_refresh_header" layout="@layout/layout_refresh_head_view" /> <android.support.v7.widget.RecyclerView android:id="@+id/swipe_target" android:layout_width="match_parent" android:layout_height="match_parent" android:scrollbars="vertical" android:clipToPadding="false"/> <include android:id="@id/swipe_load_more_footer" layout="@layout/layout_load_more_foot_view" /> </com.aspsine.swipetoloadlayout.SwipeToLoadLayout>
注意看,这里的三个控件,都有id. 区别就在控件的id这里,id不可以自己设定,需要和SwipeToLoadLayout jar包中给的id一致,如果不,会报错.
报错如下:
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.view.View.canScrollVertically(int)' on a null object reference
在SwipeToLoadLayout jar包中 给的ID我贴出来.
this.mHeaderView = this.findViewById(id.swipe_refresh_header); this.mTargetView = this.findViewById(id.swipe_target); this.mFooterView = this.findViewById(id.swipe_load_more_footer);这三个是jar中,给的id. 需要保持一致.谢谢观看,欢迎转载