我在nestedscrollview
内遇到问题recylerview
时,我加载了更多无法正常或快速滚动的页面。此外,我添加了rec_detail_videos.setNestedScrollingEnabled(false);
,这仍然使我的滚动监听器无法正常工作。简要地说,当我的滚动视图运行缓慢后,大约加载100页时。
我还尝试过对Cordinatorlayout
进行rootview操作,但是它不起作用
另外,我发现了这些链接https://stackoverflow.com/questions/44580892/recycler-view-loading-very-slow-for-large-data-when-inside-nestedscrollview
和
Bad performance when use RecyclerView inside NestedScrollView 但是我需要针对这些问题的解决方案,如何在没有代码覆盖多个recylerview的情况下弄清楚?
@androidx.annotation.RequiresApi(api = Build.VERSION_CODES.M)
public void setOtherVideoMoreAdapter() {
nestedScrollView = detailFragment.findViewById(R.id.sv_scroll);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
rec_detail_videos.setLayoutManager(linearLayoutManager);
rec_detail_videos.setNestedScrollingEnabled(false);
nestedScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
@Override
public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
if(v.getChildAt(v.getChildCount() - 1) != null) {
if ((scrollY >= (v.getChildAt(v.getChildCount() - 1).getMeasuredHeight() - v.getMeasuredHeight())) &&
scrollY > oldScrollY) {
//code to fetch more data for endless scrolling
if (videosAdapter != null) {
if(haveMoreNews) {
loadNextDataFromApi(page);
final int curSize = videosAdapter.getItemCount();
videosAdapter.notifyItemRangeInserted(curSize, videosList.size() - 1);
}
}
}
}
}
});
}
///我在下面添加了布局xml代码
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/sv_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:isScrollContainer="false"
android:layout_below="@+id/appbar"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical">
<include
android:id="@+id/layout_video_detail"
layout="@layout/layout_news_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
//包括-> layout_news_detail
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/rl_button_more"
android:layout_width="300dp"
android:layout_height="40dp"
android:layout_below="@+id/rec_other_videos"
android:layout_centerInParent="false"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:layout_marginBottom="50dp"
android:background="@drawable/ic_load_more_video"
android:visibility="gone">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="DAHA FAZLA VİDEO" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl_other_video"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/rl_info_line2"
android:layout_marginTop="10dp">
<TextView
android:id="@+id/tv_title_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:textColor="@color/aksamTv_title"
android:textStyle="bold"
app:fontFamily="@font/roboto_bold"
tools:text="Diğer Videolar" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/rec_other_videos"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/rl_other_video"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:clipToPadding="false"
android:scrollbars="vertical"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:listitem="@layout/layout_aksamtv_detail_other_videos" />
<RelativeLayout
android:id="@+id/rl_main_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/main_media_frame">
<ImageView
android:id="@+id/iv_time"
android:layout_width="wrap_content"
android:layout_height="15dp"
android:layout_below="@+id/tv_lastshort_title"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:src="@drawable/ic_access_time_black_24dp" />
<TextView
android:id="@+id/tv_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_lastshort_title"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="@+id/iv_time"
tools:text="09.04.2019" />
<TextView
android:id="@+id/tv_lastshort_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:textColor="@color/aksamTv_title"
android:textStyle="bold"
app:fontFamily="@font/roboto_bold"
tools:text="Fatih in veliahtı : Cem Sultan " />
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl_info_line"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@+id/rl_main_info"
android:layout_marginLeft="15dp"
android:layout_marginTop="2dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="2dp"
android:background="#E8E8E8" />
<RelativeLayout
android:id="@+id/rl_info_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/rl_info"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp">
<TextView
android:id="@+id/tv_info_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="" />
</RelativeLayout>
<FrameLayout
android:id="@+id/main_media_frame"
android:layout_width="match_parent"
android:layout_height="215dp"
android:background="#000000">
<com.google.android.exoplayer2.ui.SimpleExoPlayerView
android:id="@+id/detail_video_simple"
android:layout_width="match_parent"
android:layout_height="215dp"></com.google.android.exoplayer2.ui.SimpleExoPlayerView>
</FrameLayout>
<RelativeLayout
android:id="@+id/rl_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/rl_info_line">
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="false"
android:layout_marginLeft="15dp"
android:textColor="@color/aksamTv_title"
android:textStyle="bold"
app:fontFamily="@font/roboto_bold"
tools:text="DİYET MUTFAĞI" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl_info_line2"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@+id/rl_info_text"
android:layout_marginLeft="15dp"
android:layout_marginTop="5dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="2dp"
android:background="#E8E8E8" />
</RelativeLayout>
当我加载100个项目时,scrollview为何运行缓慢