我有RecyclerView
有2个布局。第一个描述主要项目,第二个描述facebook
native Ad
。它有效,但每次position
NativeViewAd
显示在显示屏上 - 我们都可以看到微滞后。
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>
和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"/>
如果您需要RecyclerAdapter.class
https://gist.github.com/burnix/d0b32f0dc4b525ec3aa7,请参阅layouts
http://www.w3schools.com/js/js_if_else.asp,但我认为layouts
中存在问题。
那我怎么解决我的问题呢?
P.S。如果height
甚至具有相同的$ cordova prepare
,则不会消失。
答案 0 :(得分:1)
我对Stackoverflow感到非常沮丧。似乎只有前青少年在这里冲浪才能回答如下问题:&#34;为什么我在onClick上有NPE?&#34; ...
这是解决方案。希望它会有用: 解决Recycler的滞后问题: 在适配器中:
Picasso.with(context)
.load(...)
.tag("resume_tag")
.into(...);
在EndlessScrollListener
班级
@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");
}
}
在课堂上,调用RecyclerView:
if (offset == 0)
adapter.notifyItemRangeInserted(0, foodDataList.size()); //or adapter.notifyDataSetChanged()
else
adapter.notifyItemRangeChanged(foodDataList.size() - jsonArray.length(), foodDataList.size());