2017-02-03 70 views
0

我的應用類似於instagram。問題出在碎片上,我有用於顯示帖子的回收站視圖。回收站視圖的第一個元素是標題,其餘是帖子。有些用戶可能有超過100個帖子,可能會有問題。我從API加載它們,但當然不是一次全部加載。我正在使用分頁 - 一個請求6個職位。接下來的部分是當我到達回收站視圖的末尾時加載的(我實現了RecyclerViewScrollListener)。帖子可以是TYPE_TEXT(僅包含文本)或TYPE_IMAGE(包含文本+圖片)的類型。圖像由Glide加載。接下來的問題是圖像具有不同的分辨率。當我向下滾動回收站視圖時是「跳躍」。如果我已經加載了很多帖子並快速向上滾動,則圖像會再次被重新加載並且回收者視圖也會「跳躍」。這樣的事情不會發生在FB,Instagram等。我不知道我做錯了什麼。這是我的代碼:有很多元素的RecyclerView工作不正確

請求回調:

public void onRequestSuccess(Post[] posts) { 
    postList.addAll(Arrays.asList(posts)); 
    adapter.notifyItemChanged(adapter.getItemCount() - posts.length - 1); // only last element has separated line 
    adapter.notifyItemRangeInserted(adapter.getItemCount() - posts.length, posts.length); 

} 

滑翔:

progress.setVisibility(View.VISIBLE); 

Glide.with(getContext()) 
    .load(post.getUri()) 
    .asBitmap() 
    .listener((new HideViewOnSuccess<String, Bitmap>(progress))) 
    .into(image); 

image_item.xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:padding="10dp" 
    > 

    <include 
     layout="@layout/item_post_header" 
     /> 

    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     > 


     <ImageView 
      android:id="@+id/image" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="@dimen/post_top_margin" 
      android:adjustViewBounds="true" 
      tools:src="@drawable/profile_placeholder" 
      android:maxHeight="420dp" 
      android:background="#FFF" 
      /> 



     <ProgressBar 
      android:id="@+id/progress" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      /> 


    </RelativeLayout> 

    <View 
     android:id="@+id/bottom_line" 
     style="@style/Bar" 
     android:layout_width="match_parent" 
     android:layout_height="1dp" 
     /> 

</LinearLayout> 
+0

http://stackoverflow.com/questions/41934901/switch-button-in-listview-randomly-changes-當滾動/ 41935212#41935212 –

回答