title: How to load images in recyclerview without affecting defined size in imageview?
body: <p>I am working with a Webservice from which I am fetching the images using retrofit.
  I am showing those images in imageView and used a recyclerview to load multiple images.<br>
  <strong>Here are my layout files:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;    
  &lt;android.support.constraint.ConstraintLayout 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:id="@+id/planscontainer"
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
       &lt;android.support.v7.widget.Toolbar
          android:id="@+id/subscplans"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_marginTop="1dp"
          android:background="?attr/colorPrimary"
          android:minHeight="?attr/actionBarSize"
          android:theme="?attr/actionBarTheme"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent"&gt;
           &lt;Button
              android:id="@+id/backplans"
              android:layout_width="30dp"
              android:layout_height="30dp"
              android:layout_marginLeft="50dp"
              android:background="@drawable/leftarrow" /&gt;
           &lt;ImageView
              android:id="@+id/appiconhere"
              android:layout_width="wrap_content"
              android:layout_height="match_parent"
              android:layout_marginStart="400dp"
              android:src="@drawable/moremovelogo" /&gt;
       &lt;/android.support.v7.widget.Toolbar&gt;
       &lt;TextView
          android:id="@+id/planname"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginStart="25dp"
          android:layout_marginTop="41dp"
          android:layout_marginEnd="319dp"
          android:text="Plan Id:"
          app:layout_constraintEnd_toStartOf="@+id/textView3"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toBottomOf="@+id/subscplans" /&gt;   
       &lt;TextView
          android:id="@+id/textView3"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginStart="324dp"
          android:layout_marginTop="41dp"
          android:layout_marginBottom="28dp"
          android:text="1"
          app:layout_constraintBottom_toTopOf="@+id/textView11"
          app:layout_constraintStart_toEndOf="@+id/planname"
          app:layout_constraintTop_toBottomOf="@+id/subscplans"
          app:layout_constraintVertical_bias="0.0" /&gt; 
       &lt;TextView
          android:id="@+id/duration"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginStart="25dp"
          android:layout_marginTop="28dp"
          android:text="Plan Name:"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toBottomOf="@+id/planname" /&gt;
       &lt;TextView
          android:id="@+id/price"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginStart="25dp"
          android:layout_marginTop="20dp"
          android:text="Price:"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toBottomOf="@+id/duration" /&gt; 
       &lt;TextView
          android:id="@+id/noofmoviesdownload"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginStart="25dp"
          android:layout_marginTop="18dp"
          android:layout_marginEnd="191dp"
          android:text="No. of movies can be download:"
          app:layout_constraintEnd_toStartOf="@+id/textView13"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toBottomOf="@+id/price" /&gt; 
       &lt;TextView
          android:id="@+id/canbeviewed"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginStart="24dp"
          android:layout_marginTop="16dp"
          android:layout_marginEnd="213dp"
          android:text="No. of movies can be viewed"
          app:layout_constraintEnd_toStartOf="@+id/textView14"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toBottomOf="@+id/noofmoviesdownload" /&gt;    
       &lt;TextView
          android:id="@+id/samemovieviewed"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginStart="25dp"
          android:layout_marginTop="24dp"
          android:layout_marginEnd="143dp"
          android:text="No. of times same movie can be viewed"
          app:layout_constraintEnd_toStartOf="@+id/textView15"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toBottomOf="@+id/canbeviewed" /&gt;    
       &lt;TextView
          android:id="@+id/timesdownload"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginStart="25dp"
          android:layout_marginTop="17dp"
          android:layout_marginEnd="126dp"
          android:text="No. of times same movie can be download"
          app:layout_constraintEnd_toStartOf="@+id/textView16"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toBottomOf="@+id/samemovieviewed" /&gt;   
       &lt;TextView
          android:id="@+id/rentpe"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginStart="26dp"
          android:layout_marginTop="18dp"
          android:layout_marginEnd="119dp"
          android:text="No. of times same movie can be get on rent"
          app:layout_constraintEnd_toStartOf="@+id/textView17"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toBottomOf="@+id/timesdownload" /&gt;    
       &lt;TextView
          android:id="@+id/textView11"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginStart="310dp"
          android:layout_marginTop="28dp"
          android:text="TextView"
          app:layout_constraintStart_toEndOf="@+id/duration"
          app:layout_constraintTop_toBottomOf="@+id/textView3" /&gt;
       &lt;TextView
          android:id="@+id/textView13"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginStart="362dp"
          android:layout_marginTop="19dp"
          android:text="TextView"
          app:layout_constraintStart_toEndOf="@+id/price"
          app:layout_constraintTop_toBottomOf="@+id/textView11" /&gt;    
       &lt;TextView
          android:id="@+id/textView14"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginStart="194dp"
          android:layout_marginTop="19dp"
          android:text="TextView"
          app:layout_constraintStart_toEndOf="@+id/noofmoviesdownload"
          app:layout_constraintTop_toBottomOf="@+id/textView13" /&gt;   
       &lt;TextView
          android:id="@+id/textView15"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginStart="216dp"
          android:layout_marginTop="15dp"
          android:layout_marginEnd="480dp"
          android:text="TextView"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toEndOf="@+id/canbeviewed"
          app:layout_constraintTop_toBottomOf="@+id/textView14" /&gt;   
       &lt;TextView
          android:id="@+id/textView16"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginStart="146dp"
          android:layout_marginTop="25dp"
          android:text="TextView"
          app:layout_constraintStart_toEndOf="@+id/samemovieviewed"
          app:layout_constraintTop_toBottomOf="@+id/textView15" /&gt;    
       &lt;TextView
          android:id="@+id/textView17"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginStart="130dp"
          android:layout_marginTop="16dp"
          android:text="TextView"
          app:layout_constraintStart_toEndOf="@+id/timesdownload"
          app:layout_constraintTop_toBottomOf="@+id/textView16" /&gt;        
       &lt;Button
          android:id="@+id/buyplan"
          android:layout_width="194dp"
          android:layout_height="wrap_content"
          android:layout_marginStart="227dp"
          android:layout_marginTop="106dp"
          android:layout_marginEnd="59dp"
          android:background="@color/tw__composer_blue"
          android:text="Buy Plan"
          android:textColor="@color/white"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toEndOf="@+id/textView13"
          app:layout_constraintTop_toBottomOf="@+id/subscplans" /&gt;    
       &lt;Button
          android:id="@+id/showplans"
          android:layout_width="194dp"
          android:layout_height="wrap_content"
          android:layout_marginStart="224dp"
          android:layout_marginTop="37dp"
          android:layout_marginEnd="62dp"
          android:layout_marginBottom="229dp"
          android:background="#d156b8"
          android:text="Show plans"
          android:textColor="@color/white"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toEndOf="@+id/textView15"
          app:layout_constraintTop_toBottomOf="@+id/buyplan"
          app:layout_constraintVertical_bias="0.0" /&gt;  
       &lt;TextView
          android:id="@+id/textView19"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginStart="121dp"
          android:layout_marginTop="19dp"
          android:text="TextView"
          app:layout_constraintStart_toEndOf="@+id/rentpe"
          app:layout_constraintTop_toBottomOf="@+id/textView17" /&gt;
        &lt;RelativeLayout
          android:id="@+id/linearlayoutimage"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginTop="20dp"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toBottomOf="@id/textView19"&gt;  
           &lt;android.support.v7.widget.RecyclerView
              android:id="@+id/myrecyclerview"
              android:orientation="horizontal"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"&gt;
           &lt;/android.support.v7.widget.RecyclerView&gt;
       &lt;/RelativeLayout&gt;
       &lt;Button
          android:id="@+id/cancelplan"
          android:layout_width="194dp"
          android:layout_height="wrap_content"
          android:layout_marginStart="221dp"
          android:layout_marginTop="37dp"
          android:layout_marginEnd="60dp"
          android:background="@color/tw__composer_deep_gray"
          android:text="cancel plan"
          android:textColor="@color/white"
          android:visibility="gone"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toEndOf="@+id/textView17"
          app:layout_constraintTop_toBottomOf="@+id/showplans" /&gt; 
  &lt;/android.support.constraint.ConstraintLayout&gt;
  </code></pre>
  
  <p><strong>and for the items I have:</strong></p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"   
    &gt;  
      &lt;ImageView
          android:id="@+id/imagethumb"
          android:layout_width="180dp"
          android:layout_height="200dp"
          android:scaleType="fitEnd"/&gt;    
      &lt;TextView
          android:id="@+id/nothing"
          android:visibility="gone"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" /&gt;   
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>And my Adapter class looks like:
  this is my adapter class name <strong>ImageAdapter.java</strong></p>
  
  <pre><code>public class ImageAdapter extends RecyclerView.Adapter&lt;ImageAdapter.SubsImageHolder&gt; {
  
      DisplayImageOptions options = new DisplayImageOptions.Builder()
              .showImageOnLoading(R.drawable.newlogo)
              .showImageForEmptyUri(R.drawable.newlogo)
              .showImageOnFail(R.drawable.newlogo)
              .cacheInMemory(true)
              .cacheOnDisk(true)
              .considerExifParams(true)
              .bitmapConfig(Bitmap.Config.RGB_565)
              .build();
  
      private Context context;
      private List&lt;ThumbPojo&gt; imageList;
  
      public ImageAdapter(Context context, List&lt;ThumbPojo&gt; items) {
          this.context = context;
          this.imageList = items;
      }
  
      public Context getContext() {
          return context;
      }
  
      public void setContext(Context context) {
          this.context = context;
      }
  
      public List&lt;ThumbPojo&gt; getImageList() {
          return imageList;
      }
  
      public void setImageList(List&lt;ThumbPojo&gt; imageList) {
          this.imageList = imageList;
      }
  
      @NonNull
      @Override
      public SubsImageHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
          LayoutInflater layoutInflater = LayoutInflater.from(context);
          View view = layoutInflater.inflate(R.layout.subscriptionimages, viewGroup, false);
          return new SubsImageHolder(view);
      }
  
      @Override
      public void onBindViewHolder(@NonNull SubsImageHolder subsImageHolder, int i) {
         ThumbPojo item = imageList.get(i);
          subsImageHolder.textView.setText(item.getMovieName());
          subsImageHolder.imageView.setImageDrawable(null);
          subsImageHolder.imageView.layout(0,0,0,0);
  
          ImageLoader.getInstance().displayImage(item.getThumbnail(),subsImageHolder.imageView,options);
  
  //        Glide.with(context)
  //                .load(item.getThumbnail())
  //                .into(subsImageHolder.imageView);
  
      }
  
      @Override
      public int getItemCount() {
          return imageList.size();
      }
  
       class SubsImageHolder extends RecyclerView.ViewHolder {
  
          ImageView imageView;
          TextView textView;
  
          public SubsImageHolder(@NonNull View itemView) {
  
              super(itemView);
              imageView = itemView.findViewById(R.id.imagethumb);
              textView = itemView.findViewById(R.id.nothing);
          }
      }
  }
  </code></pre>
  
  <p>And my Main Activity where I am setting my adpater is :
  <strong>SubscriptionPlans.java:</strong></p>
  
  <pre><code> public class SubscriptionPlans extends AppCompatActivity {
  
      TextView planid, planname, planprice, noofmoviedownload, noofmovieviewed, sameviewed, samedownload, rentit, nomovi;
      Intent intent = getIntent();
      ImageView imageView3, imageView4;
      String one, two, three, four, five, six, seven, eight;
      List&lt;ThumbPojo&gt; list;
      Button button;
      Button show, buy, cancel;
      int position;
      String allvalues;
      RelativeLayout linearLayout;
      String id;
      int userid, usertype;
      int po;
      String ress;
      public String subs;
  
      List&lt;CheckActiveOrNot&gt; list1;
  
      RecyclerView recyclerView;
      ImageAdapter imageAdapter;
      List&lt;ThumbPojo&gt; imageList; 
      List&lt;String&gt; images = new ArrayList&lt;&gt;();
      AVLoadingIndicatorView progressBar;
  
      @Override
      protected void onCreate(@Nullable Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.premiumsubscriptionplans);
  //        progressBar=findViewById(R.id.progressBar);
  //        showProgressDialog();
  
         * recyclerView = findViewById(R.id.myrecyclerview);
          recyclerView.setLayoutManager(new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,false));*
  
          userid = SharedPrefsHelper.getUserId(SharedPrefsHelper.USER_ID, 0);
          usertype = SharedPrefsHelper.getUserType(SharedPrefsHelper.USER_TYPE, 0);
  
  
  
          linearLayout = findViewById(R.id.linearlayoutimage);
  
          //  imageView4 = findViewById(R.id.imageView4);
          planid = findViewById(R.id.textView3);
          planname = findViewById(R.id.textView11);
          planprice = findViewById(R.id.textView13);
          noofmoviedownload = findViewById(R.id.textView14);
          noofmovieviewed = findViewById(R.id.textView15);
          sameviewed = findViewById(R.id.textView16);
          samedownload = findViewById(R.id.textView17);
          rentit = findViewById(R.id.textView19);
          TextView notshow = findViewById(R.id.planname);
          notshow.setVisibility(View.GONE);
          planid.setVisibility(View.GONE);
  
          button = findViewById(R.id.backplans);
          show = findViewById(R.id.showplans);
          buy = findViewById(R.id.buyplan);
          cancel = findViewById(R.id.cancelplan);
  
  
          id = getIntent().getStringExtra("planid");
          imageList = new ArrayList&lt;&gt;();
  
          Call&lt;List&lt;ThumbPojo&gt;&gt; caller = ApiClient.getInstance().getApiService().getThumbimages(id);
          caller.enqueue(new Callback&lt;List&lt;ThumbPojo&gt;&gt;() {
              @Override
              public void onResponse(Call&lt;List&lt;ThumbPojo&gt;&gt; call, Response&lt;List&lt;ThumbPojo&gt;&gt; response) {
                  list =response.body();
  
  //                JSONArray jsonArray=new JSONArray(list);
  //                for(int i=0;i&lt;jsonArray.length();i++)
  //                {
  //                    try {
  //                        JSONObject jsonObject=jsonArray.getJSONObject(i);
  //                        String name=jsonObject.getString("movieName");
  //                        String imageurl=jsonObject.getString("thumbnail");
  //
  //                        ThumbPojo thumbPojo=new ThumbPojo(name,imageurl);
  //                        imageList.add(thumbPojo);
  //                    } catch (JSONException e) {
  //                        e.printStackTrace();
  //                    }
  //
  //                }
  
                  *imageAdapter=new ImageAdapter(SubscriptionPlans.this,list);
                  recyclerView.setHasFixedSize(true);
                  recyclerView.setAdapter(imageAdapter);
  //                dismissProgressDialog();*
  
  //                if (list.get(position).getThumbnail() != null) {
  //                    ImageLoader.getInstance().displayImage(list.get(position).getThumbnail(), imageView3, options);
  //                    // ImageLoader.getInstance().displayImage(list.get(position).getThumbnail(),imageView4,options);
  //                } else {
  //                    nomovi.setText("No movies under this plan");
  //                }
  
  
              }
  
  
              @Override
              public void onFailure(Call&lt;List&lt;ThumbPojo&gt;&gt; call, Throwable t) {
                  t.getMessage();
              }
          });
  </code></pre>
  
  <p>for <em>image loading</em> purposes I am using universal image loader.
  Now coming to the problem, when a single image is coming from the server then it is loaded according to the width and height mentioned in the imageview .but when two or more are coming the images' sizes are different.</p>
  
  <p><a href="https://i.stack.imgur.com/I2Knt.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/I2Knt.jpg" alt="images looks like this"></a></p>
  
  <p>I have tried almost all the solution from the internet but nothing works fine.
  I have also set the layout to (0,0,0,0) but that also not able to fix this.</p>
  
  <p>Images are looking like this I don't know why?</p>