我正在开发和应用程序,应该在recyclelerview中显示用户Instagram帖子...我正确地获取所有数据但是在我滚动我的recyclerview图片后弄得一团糟,一张图片显示两次......以及我列表中的其他混乱。 这是我在Recyclerview中的onbind View holder扩展了RecyclerView.Adapter:
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
Picasso.with(context).
load(imageThumbList.get(position)
).
into(ivimage);
igetPositionImage.getPosition(position);
/*imageLoader.DisplayImage(imageThumbList.get(position), ivimage);*/
count_like.setText(likeCounts.get(position));
以及我在片段中调用的回收视图:
private void setImageGridAdapter() {
recyclerView = (RecyclerView) getView().findViewById(R.id.recycler_view);
RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(getActivity(),3);
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.addItemDecoration(new GridSpacingItemDecoration(1, dpToPx(1), true));
recyclerView.setItemAnimator(new DefaultItemAnimator());
RecycleListAdapter recycleListAdapter = new RecycleListAdapter(getActivity(),imageThumbList , likeCounts ,LikeGetterF.this);
recyclerView.setAdapter(recycleListAdapter);
Paginate.with(recyclerView , callbacks)
.setLoadingTriggerThreshold(2).
addLoadingListItem(true).
setLoadingListItemCreator(new RecycleListAdapter(getActivity(),imageThumbList,likeCounts,LikeGetterF.this))
.setLoadingListItemSpanSizeLookup(new RecycleListAdapter(getActivity(),imageThumbList,likeCounts,LikeGetterF.this))
.build();
//gvAllImages.setAdapter(new MyGridListAdapter(context,imageThumbList));
}
和我的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="match_parent"
android:orientation="vertical"
android:id="@+id/all_media_files"
>
<!-- <ListView -->
<!-- android:id="@+id/lvImages" -->
<!-- android:layout_width="fill_parent" -->
<!-- android:layout_height="wrap_content" > -->
<!-- </ListView> -->
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:background="#AFAFAFAF"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="true"
android:scrollbars="horizontal" />
</LinearLayout>
和我的项目适配器xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="20dp"
>
<FrameLayout
android:layout_width="100dp"
android:layout_height="100dp"
>
<ImageView
android:id="@+id/ivImage"
android:layout_width="100dp"
android:layout_height="100dp"
android:clickable="true"
android:scaleType="fitCenter"
android:src="@drawable/profile"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="bottom"
android:background="#AFAFAFAF"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:src="@drawable/like_red"
android:id="@+id/like_img"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:text="0"
android:gravity="right"
android:textColor="@color/textColorPrimary"
android:textSize="@dimen/buttonSizes"
android:id="@+id/like_count"
/>
</LinearLayout>
</FrameLayout>
<!-- android:background="@drawable/char_02"-->
</LinearLayout>
答案 0 :(得分:0)
删除绑定持有者中的最终位置,
public void onBindViewHolder(RecyclerView.ViewHolder holder,int position){
int adapterPos = holder.getAdapterPosition();
Picasso.with(上下文)。
load(imageThumbList.get(adapterPos)
).
into(ivimage);
igetPositionImage.getPosition(位置);
holder.setIsRecyclable(假);
/*imageLoader.DisplayImage(imageThumbList.get(position), ivimage);*/
count_like.setText(likeCounts.get(位置));
并在bindView holder
中的任何地方使用adapterPos