1、在項目中一個頁面存在兩個recyclerview,在底部recyclerview下拉刷新時,不能自動滾動
代碼如下:
<com.scwang.smartrefresh.layout.SmartRefreshLayout
android:id="@+id/refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:srlEnableAutoLoadMore="true"
app:srlEnableLoadMore="true"
app:srlEnableRefresh="true">
<cn.ipets.chongmingandroid.ui.widget.recyclerview.ClassicsHeader
android:id="@+id/classics_header"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="UnusedAttribute">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/tv_recommend"
style="@style/TextViewFontMedium"
android:layout_width="match_parent"
android:layout_height="@dimen/dp34"
android:gravity="center_vertical"
android:paddingStart="@dimen/dp15"
android:text="推薦關注"
android:textColor="@color/colorGrayText1"
android:textSize="@dimen/font_size_14sp"
android:visibility="gone" />
<com.chongminglib.view.VpRecyclerView
android:id="@+id/recyclerview_recommend"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
tools:targetApi="lollipop" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/tv_fans"
style="@style/TextViewFontMedium"
android:layout_width="match_parent"
android:layout_height="@dimen/dp34"
android:gravity="center_vertical"
android:paddingStart="@dimen/dp15"
android:text="我的粉絲"
android:textColor="@color/colorGrayText1"
android:textSize="@dimen/font_size_14sp"
android:visibility="gone" />
<com.chongminglib.view.VpRecyclerView
android:id="@+id/recyclerview_fans"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:targetApi="lollipop" />
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<cn.ipets.chongmingandroid.ui.widget.recyclerview.ClassicsFooter
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.scwang.smartrefresh.layout.SmartRefreshLayout>
2、問題解決
百度了 BaseRecyclerViewAdapterHelper庫的issues得到答案
鏈接:https://github.com/CymChad/BaseRecyclerViewAdapterHelper/issues/1510
recyclerview.setHasFixedSize(true)
setHasFixedSize的作用是讓固定類型的item更有優勢。
註銷掉該方法完美解決!