在我的应用程序中,我正在使用tabHost Activiy.在tabhost第一个选项卡中,我正在使用TabActivity,我正在加载超过500个图像.
使用嵌套的SCroll视图:
我在recyclerview中使用了嵌套滚动视图.当加载主页时,它最初加载所有500个图像,然后显示主页.因此它会导致内存错误.
不使用嵌套的SCroll视图:
如果我删除嵌套滚动视图,一切都运行良好.滚动时逐个加载图像.它不会导致内存不足错误.
我的要求:
我需要滚动放置在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>
Run Code Online (Sandbox Code Playgroud)
下面我愿意分享我到目前为止所尝试的内容.
我试过这个SO帖子.但是我在tabActivity里面使用主页.所以我不能使用工具栏+协调器布局.所以这个解决方案对我没用.
然后我尝试使用多个布局 进行recyclerview.But这对我不起作用.因为relativelayout是静态的.如果我从webservice获得任何条件,我可以使用多个布局recyclerview.But我需要只是滚动视图.
我计划设置adapter.But我的web服务图像被加载从第0 position.So我不能设置在零位置在适配器静态的RelativeLayout的第0位静态RelativeLayout的.
是否有任何替代解决方案来解决这个问题.谢谢.