在我的应用程序中,我正在使用TabHost Activity。在TabHost的第一个标签中,我正在使用TabActivity,加载了500多张图片。
使用嵌套滚动视图:
我在RecyclerView中使用了嵌套滚动视图。当加载主页时,它首先加载所有500张图像,然后显示主页。因此,这会导致内存溢出错误。
不使用嵌套滚动视图:
如果我删除嵌套滚动视图,一切都很好。它会在滚动时逐个加载图像,不会导致内存不足错误。
我的要求:
我需要滚动放置在RecyclerView顶部的相对布局。因此,我使用了嵌套滚动视图。但它对我没有起作用。
tab_home_layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
>
<LinearLayout
android:id="@+id/tab_home_activity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<RelativeLayout
android:id="@+id/home_layout_top_2_recycler"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@drawable/layout_border"
>
<ImageView
android:id="@+id/img_user_home_tab_recycler"
android:layout_width="40dp"
android:layout_height="40dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:layout_centerVertical="true"
android:contentDescription="@string/cont_desc"
android:src="@drawable/profile_pic_blue" />
<TextView
android:id="@+id/tv_user_mind_home_tab_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_toRightOf="@+id/img_user_home_tab_recycler"
android:hint="@string/whats_on"
android:textColor="@color/Black"
android:textSize="@dimen/txt_size" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_list_tab_home_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:visibility="visible" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
以下是我尝试过的内容。
然后我尝试使用多个布局用于RecyclerView。但那对我没有用。因为那个RelativeLayout是静态的。如果我从网络服务获得任何条件,我可以使用多个布局RecyclerView。但我需要滚动视图。
我计划在适配器的第0个位置设置静态RelativeLayout。但我的网络服务图像从第0个位置开始加载。所以我不能将静态RelativeLayout设置在适配器的第0个位置。
是否有其他替代解决方案来解决这个问题。谢谢。
requestDisallowInterceptTouchEvent()
吗?更多信息请参见:https://developer.android.com/reference/android/view/ViewGroup.html#requestDisallowInterceptTouchEvent(boolean) 和 https://developer.android.com/training/gestures/viewgroup.html。 - milosmns