title: How to improve my RecyclerView performance with large size photos inside the my App?
body: <p>I create one RecyclerView in may app and it work slowly and not quick .</p>
  
  <p>this is my adapter</p>
  
  <pre><code>public class PostAdapter extends 
  RecyclerView.Adapter&lt;RecyclerView.ViewHolder&gt; {
  
  private Context context;
  private List&lt;PostDataModel&gt; models;
  
  public static final String TITLE = "title";
  public static final String CONTENT = "content";
  public static final String IMAGE_DIR = "image_dir";
  
  
  
  public PostAdapter(Context context, List&lt;PostDataModel&gt; models) {
      this.context = context;
      this.models = models;
  }
  
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int  
           viewType) {
          View view = 
    LayoutInflater.from(context).inflate(R.layout.post_layout, parent, false);
          return new PostViewHolder(view);
  
    }
  
   @Override
   public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) 
   {
      if (holder instanceof PostViewHolder) {
          final PostDataModel model = models.get(position);
          PostViewHolder viewHolder = (PostViewHolder)holder;
  
      Picasso.with(context).load(model.getImage_dir()).into(viewHolder.image);
          viewHolder.title.setText(model.getTitle());
          viewHolder.content.setText(model.getContent());
          viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Intent intent = new Intent(context, PostActivity.class);
                  intent.putExtra(IMAGE_DIR, model.getImage_dir());
                  intent.putExtra(TITLE, model.getTitle());
                  intent.putExtra(CONTENT, model.getContent());
                  context.startActivity(intent);
              }
          });
      }
  
  
   }
  
   @Override
   public int getItemCount() {
      return models.size() ;
  }
  
  
   public class PostViewHolder extends RecyclerView.ViewHolder{
          private ImageView image;
          private TextView title;
          private TextView content;
      public PostViewHolder(View itemView) {
          super(itemView);
          image = itemView.findViewById(R.id.image_view);
          title =  itemView.findViewById(R.id.txt_title);
          content = itemView.findViewById(R.id.txt_content);
      }
    }
  }
  </code></pre>
  
  <p>and this is my DataFakeGenerator :</p>
  
  <pre><code>public class PostFakeGenerator {
  
  public static List&lt;PostDataModel&gt; getData(Context context){
      List&lt;PostDataModel&gt; models = new ArrayList&lt;&gt;();
      for (int i = 0; i &lt;10 ; i++) {
          PostDataModel model = new PostDataModel();
          switch (i){
              case 0:
                  model.setTitle("post "+i);
                  model.setContent("Lorem Ipsum");     
    model.setImage(ResourcesCompat.getDrawable(context.getResources(),
                   R.drawable.horse1,null));
                  model.setImage_dir(R.drawable.horse1);
                  break;
              case 1:
                  model.setTitle("post "+i);
                  model.setContent("Lorem Ipsum");                    
     model.setImage(ResourcesCompat.getDrawable(context.getResources(),
                    R.drawable.horse2,null));
                  model.setImage_dir(R.drawable.horse2);
                  break;
  
              case 2:
                  model.setTitle("post "+i);
                  model.setContent("Lorem Ipsum." );                    
         model.setImage(ResourcesCompat.getDrawable(context.getResources(),
                        R.drawable.horse3,null));
                  model.setImage_dir(R.drawable.horse3);
                  break;
  
              case 3:
                  model.setTitle("post "+i);
                  model.setContent("Lorem Ipsum.");                    
     model.setImage(ResourcesCompat.getDrawable(context.getResources(),
                    R.drawable.horse4,null));
                  model.setImage_dir(R.drawable.horse4);
                  break;
  
              case 4:
                  model.setTitle("post "+i);
                  model.setContent("Lorem Ipsum.");                    
           model.setImage(ResourcesCompat.getDrawable(context.getResources(),
                          R.drawable.horse5,null));
                  model.setImage_dir(R.drawable.horse5);
                  break;
  
              case 5:
                  model.setTitle("post "+i);
                  model.setContent("Lorem Ipsum.");                   
      model.setImage(ResourcesCompat.getDrawable(context.getResources(),
                     R.drawable.horse6,null));
                  model.setImage_dir(R.drawable.horse6);
                  break;
          }
  
          models.add(model);
  
       }
        return models;
    }
  
  
  }
  </code></pre>
  
  <p>this is my Activity :</p>
  
  <pre><code>public class MyNoticeActivity extends AppCompatActivity {
  
   private RecyclerView recyclerView;
   private PostAdapter adapter;
   private boolean grid;
  
    @Override
    protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_my_notice_activity);
  
      setupRecyclerView();
      setupToolbar();
  
  }
  
  public void setupToolbar(){
      Toolbar toolbar = findViewById(R.id.toolbar_my_notice);
       setSupportActionBar(toolbar);
      ActionBar actionBar = getSupportActionBar();
      actionBar.setHomeButtonEnabled(true);
      actionBar.setDisplayHomeAsUpEnabled(true);
  
      toolbar.setNavigationOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              finish();
          }
      });
  }
  
  public void setupRecyclerView(){
      adapter = new PostAdapter(this, PostFakeGenerator.getData(this));
      recyclerView = findViewById(R.id.recycler);
      showAlphaAnimation(recyclerView);
      recyclerView.setLayoutManager(new StaggeredGridLayoutManager
                               (2,StaggeredGridLayoutManager.VERTICAL));
      grid = true;
      recyclerView.setAdapter(adapter);
  }
  
  public void showAlphaAnimation(View view){
      AlphaAnimation alphaAnimation = new AlphaAnimation(0.0f,1.0f);
      alphaAnimation.setDuration(1000);
      alphaAnimation.setFillAfter(true);
      view.startAnimation(alphaAnimation);
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      getMenuInflater().inflate(R.menu.my_notic_activity_menu,menu);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      switch (item.getItemId()){
          case R.id.change_layout_manager:
              if (grid) {
                  recyclerView.setLayoutManager(new LinearLayoutManager(this, 
                                      LinearLayoutManager.VERTICAL, false));
                  grid = false ;
                  recyclerView.setAdapter(adapter);
                  item.setIcon(R.drawable.vc_grid_layout_manager);
              }else {
                  recyclerView.setLayoutManager(new StaggeredGridLayoutManager
                                     (2,StaggeredGridLayoutManager.VERTICAL));
                  grid = true;
                  recyclerView.setAdapter(adapter);
                  item.setIcon(R.drawable.vc_list_layout_manager);
              }
              break;
      }
      return super.onOptionsItemSelected(item);
    }
  }
  </code></pre>
  
  <p>this is my layout activity :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.davod.a4nal.Activity.MyNoticeActivity"
    android:layoutDirection="rtl"&gt;
  
  &lt;android.support.design.widget.AppBarLayout
      android:id="@+id/app_bar_layout_city"
      app:theme="@style/Base.ThemeOverlay.AppCompat.Dark"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"&gt;
  
      &lt;android.support.v7.widget.Toolbar
          android:id="@+id/toolbar_my_notice"
          android:background="@color/colorPrimary"
          app:layout_scrollFlags="scroll|enterAlways"
          android:layout_width="match_parent"
          android:layout_height="?attr/actionBarSize"&gt;
          &lt;com.example.davod.a4nal.Custom.CustomFontTextView
              android:text="انتخاب شهر"
              android:textSize="@dimen/standard_size_title"
              android:textColor="@color/white"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content" /&gt;
  
      &lt;/android.support.v7.widget.Toolbar&gt;
   &lt;/android.support.design.widget.AppBarLayout&gt;
  
  
  
      &lt;android.support.v7.widget.RecyclerView
          android:id="@+id/recycler"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          app:layout_behavior="@string/appbar_scrolling_view_behavior"/&gt;
  
  &lt;/android.support.design.widget.CoordinatorLayout&gt;
  </code></pre>
  
  <p>and this is my sample of post in recyclerView :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.constraint.ConstraintLayout
   android:padding="8dp"
   xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:app="http://schemas.android.com/apk/res-auto"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"&gt;
  
  &lt;ImageView
      android:id="@+id/image_view"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:adjustViewBounds="true"
      android:scaleType="centerCrop"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toTopOf="parent"
      tools:src="@drawable/horse_banner_1" /&gt;
  
  &lt;TextView
      android:id="@+id/txt_title"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginStart="16dp"
      android:layout_marginTop="8dp"
      android:textColor="@color/text_title_color"
      android:textSize="@dimen/standard_size_title"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toBottomOf="@+id/image_view"
      tools:text="title" /&gt;
  
  &lt;TextView
      android:id="@+id/txt_content"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginTop="8dp"
      android:maxLines="3"
      android:ellipsize="end"
      android:textColor="@color/text_title_color"
      android:textSize="@dimen/standard_size_content"
      app:layout_constraintStart_toStartOf="@+id/txt_title"
      app:layout_constraintTop_toBottomOf="@+id/txt_title"
      tools:text="afsdfh jahf kjsajkfg skjdgfjk sjdgf sdgf " /&gt;
  &lt;/android.support.constraint.ConstraintLayout&gt;
  </code></pre>
  
  <p>what am I doing to improve performance and app work quickly ?
  I decrease size of photo and still work slowly .
  I change layouts from Liner Layout to Constraint Layout and didn't work .
  do you have a solution for me ?
  tanks. </p>