android - Lags in multiple layouts RecyclerView -
i have recyclerview 2 layouts. first 1 describes main item , second facebook native ad. works, every time position nativeviewad shown on display - can see micro-lags.
recycler_item.xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="250dp" android:orientation="vertical" android:padding="8dp" android:id="@+id/list_item"> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content"> <imageview android:id="@+id/food_picture" android:layout_width="match_parent" android:layout_height="wrap_content" android:adjustviewbounds="true" android:src="@drawable/blank2" /> </linearlayout> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <textview android:id="@+id/title" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text="@string/test_name_food" android:textappearance="?android:attr/textappearancemedium" android:textcolor="#242424" android:paddingtop="4dp" /> </linearlayout> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:paddingleft="8dp" android:paddingbottom="8dp" android:paddingright="8dp" android:paddingtop="4dp"> <textview android:id="@+id/ingr_count" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/test_name_ingr" android:textappearance="?android:attr/textappearancesmall" android:layout_weight="1" android:textalignment="center" android:layout_gravity="center_vertical" android:gravity="center" /> <!-- <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:layout_weight="33"> <imageview android:id="@+id/ic_ingredient" android:layout_width="24dp" android:layout_height="24dp" android:src="@drawable/ic_ingredient" android:layout_gravity="center_vertical" android:layout_weight="1" android:paddingright="8dp" /> <imageview android:id="@+id/ic_time" android:layout_width="24dp" android:layout_height="24dp" android:src="@drawable/ic_time" android:layout_gravity="center_vertical|right" android:layout_weight="1" android:paddingleft="8dp" /> </linearlayout> --> <textview android:id="@+id/look" android:layout_width="match_parent" android:layout_height="match_parent" android:text="Просмотреть" android:textappearance="?android:attr/textappearancesmall" android:layout_gravity="center" android:textalignment="center" android:gravity="center" android:textcolor="#4caf50" android:textstyle="bold" android:typeface="normal" android:layout_weight="1" /> </linearlayout> </linearlayout> and additional.xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="300dp" android:orientation="vertical" android:id="@+id/ad_test2" android:background="@drawable/blank2"> <imageview android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/blank2" android:id="@+id/blank_holder"/> here's gist of recycleradapter.class https://gist.github.com/burnix/d0b32f0dc4b525ec3aa7 if need, suppose, there problem in 1 of layouts.
so how can solve issue?
p.s. if layouts have same height, lags don't disappear.
i upset stackoverflow. seems, pre-juniors surfing here answering questions like:"why have npe in onclick?"...
here solution. hope useful: solve lags in recycler: in adapter:
picasso.with(context) .load(...) .tag("resume_tag") .into(...); in endlessscrolllistener class
@override public void onscrollstatechanged(recyclerview recyclerview, int newstate) { super.onscrollstatechanged(recyclerview, newstate); final picasso picasso = picasso.with(context); if (newstate == recyclerview.scroll_state_idle) { picasso.resumetag("resume_tag"); } else { picasso.pausetag("resume_tag"); } } in class, calls recyclerview:
if (offset == 0) adapter.notifyitemrangeinserted(0, fooddatalist.size()); //or adapter.notifydatasetchanged() else adapter.notifyitemrangechanged(fooddatalist.size() - jsonarray.length(), fooddatalist.size());
Comments
Post a Comment