Android-MaterialRefreshLayout
Android-MaterialRefreshLayout copied to clipboard
布局中使用app:overlay="false" 与autoRefresh(); 同时使用会出现NullPointException
报错代码
public void autoRefresh()
{
updateListener();
if(isOverlay)
{
mHeadLayout.getLayoutParams().height = (int) mHeadHeight;
mHeadLayout.requestLayout();
}else
{
createAnimatorTranslationY(mChildView, mHeadHeight, mHeadLayout);
}
}
在程序执行到mHeadLayout.getLayoutParams().height = (int) mHeadHeight; 时出现空指针 布局文件如下
<com.cjj.MaterialRefreshLayout
android:id="@+id/refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/buyCarLayout"
android:layout_below="@id/productsOptions"
app:isLoadMore="true"
app:overlay="true"
app:wave_show="false">
<android.support.v7.widget.RecyclerView
android:id="@+id/products"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</com.cjj.MaterialRefreshLayout>
不能在主线程直接去刷新,作者的demo里有的。 public void autoRefresh() { if (!isRefreshing) { this.postDelayed(new Runnable() { @Override public void run() { updateListener(); if (isOverlay) { mHeadLayout.getLayoutParams().height = (int) mHeadHeight; mHeadLayout.requestLayout(); } else { createAnimatorTranslationY(mChildView, mHeadHeight, mHeadLayout); } } }, 500); } }
表示直接down下作者的Demo到自己项目当中引用,就不会出现该NullPointException的问题。