title: Why are my "posts" loading in different sizes in android recyclerview?
body: <p>Okay, this is how my recyclerview is showing my "posts". Can anyone tell me why? I will post source code as well. I have tried changing some of the code with no success. Also, when I scroll through my RecyclerView, some of them resize to smaller or larger sizes. Any and all help is appreciated!</p>
  
  <p><a href="https://i.stack.imgur.com/38I0a.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/38I0a.png" alt="This is what my RecyclerView looks like when it loads. Also, when I scroll, some of the resize to other smaller or larger sizes."></a></p>
  
  <p>fragment_home.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
      &lt;android.support.v7.widget.RecyclerView
          android:id="@+id/recyclerView"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:background="#fff" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>list_item.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      android:id="@+id/listItemLayout"&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="horizontal"&gt;
  
          &lt;ImageButton
              android:id="@+id/yesButton"
              android:layout_width="0dp"
              android:layout_height="40dp"
              android:layout_weight="1"
              android:background="#00FF00" /&gt;
  
          &lt;ImageButton
              android:id="@+id/noButton"
              android:layout_width="0dp"
              android:layout_height="40dp"
              android:layout_weight="1"
              android:background="#FF0000" /&gt;
  
      &lt;/LinearLayout&gt;
  
      &lt;com.android.volley.toolbox.NetworkImageView
          android:id="@+id/image_1"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:src="@drawable/placeholder" /&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:padding="5dp"
          android:background="#509f9f9f"
          android:orientation="horizontal"&gt;
  
          &lt;LinearLayout
              android:layout_width="0dp"
              android:layout_height="wrap_content"
              android:layout_weight="8"
              android:orientation="horizontal"&gt;
  
              &lt;com.android.volley.toolbox.NetworkImageView
                  android:id="@+id/thumbnail"
                  android:layout_width="40dp"
                  android:layout_height="40dp"
                  android:scaleType="fitXY"
                  android:src="@drawable/placeholder" /&gt;
  
              &lt;TextView
                  android:id="@+id/pUsername"
                  android:layout_marginLeft="5dp"
                  android:layout_marginStart="5dp"
                  android:gravity="center_vertical"
                  android:layout_width="wrap_content"
                  android:layout_height="match_parent"
                  android:text="username" /&gt;
  
          &lt;/LinearLayout&gt;
  
          &lt;LinearLayout
              android:layout_width="0dp"
              android:layout_height="wrap_content"
              android:layout_weight="1"
              android:orientation="horizontal"&gt;
  
              &lt;ImageButton
                  android:id="@+id/postMenu"
                  android:layout_width="match_parent"
                  android:layout_height="40dp"
                  android:background="#000"/&gt;
  
          &lt;/LinearLayout&gt;
  
      &lt;/LinearLayout&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>LruBitmapCache.java:</p>
  
  <pre><code>public class LruBitmapCache extends LruCache&lt;String, Bitmap&gt; implements ImageCache {
  
      public LruBitmapCache(int maxSize) {
          super(maxSize);
      }
  
      public LruBitmapCache(Context context) {
          this(getCacheSize(context));
      }
  
      @Override
      protected int sizeOf(String key, Bitmap value) {
          return value.getRowBytes() * value.getHeight();
      }
  
      @Override
      public Bitmap getBitmap(String url) {
          return get(url);
      }
  
      @Override
      public void putBitmap(String url, Bitmap bitmap) {
          put(url, bitmap);
      }
  
      public static int getCacheSize(Context context) {
          final DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
          final int screenWidth = displayMetrics.widthPixels;
          final int screenHeight = displayMetrics.heightPixels;
          final int screenBytes = screenWidth * screenHeight * 4;
  
          return screenBytes * 3;
      }
  
  }
  </code></pre>
  
  <p>MyRecyclerAdapter.java:</p>
  
  <pre><code>public class MyRecyclerAdapter extends RecyclerView.Adapter&lt;ListRowViewHolder&gt; {
  
      private List&lt;ListItems&gt; listItemsList;
      private Context mContext;
      private ImageLoader mImageLoader;
  
      private int focusedItem = 0;
  
      public MyRecyclerAdapter(Context context, List&lt;ListItems&gt; listItemsList) {
          this.mContext = context;
          this.listItemsList = listItemsList;
      }
  
      @Override
      public ListRowViewHolder onCreateViewHolder(final ViewGroup viewGroup, int position) {
          View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.list_item, null);
          ListRowViewHolder holder = new ListRowViewHolder(v);
  
          return holder;
      }
  
      @Override
      public void onBindViewHolder(final ListRowViewHolder listRowViewHolder, int position) {
          ListItems listItems = listItemsList.get(position);
          listRowViewHolder.itemView.setSelected(focusedItem == position);
  
          listRowViewHolder.getLayoutPosition();
  
          mImageLoader = MySingleton.getInstance(mContext).getImageLoader();
  
          listRowViewHolder.thumbnail.setImageUrl(listItems.getProfilePicture(), mImageLoader);
          listRowViewHolder.thumbnail.setDefaultImageResId(R.drawable.placeholder);
  
          listRowViewHolder.image_1.setImageUrl(listItems.getImage_1(), mImageLoader);
          listRowViewHolder.image_1.setDefaultImageResId(R.drawable.placeholder);
  
          listRowViewHolder.username.setText(Html.fromHtml(listItems.getUsername()));
      }
  
      public void clearAdapter() {
          listItemsList.clear();
          notifyDataSetChanged();
      }
  
      @Override
      public int getItemCount() {
          return (null != listItemsList ? listItemsList.size() : 0);
      }
  
  }
  </code></pre>
  
  <p>MySingleton.java:</p>
  
  <pre><code>public class MySingleton {
  
      private static MySingleton mInstance;
      private RequestQueue mRequestQueue;
      private ImageLoader mImageLoader;
      private static Context mContext;
  
      private MySingleton(Context context) {
          mContext = context;
          mRequestQueue = getRequestQueue();
  
          mImageLoader = new ImageLoader(mRequestQueue, new LruBitmapCache(LruBitmapCache.getCacheSize(mContext)));
      }
  
      public static synchronized MySingleton getInstance(Context context) {
          if (mInstance == null) {
              mInstance = new MySingleton(context);
          }
          return mInstance;
      }
  
      public RequestQueue getRequestQueue() {
          if (mRequestQueue == null) {
              mRequestQueue = Volley.newRequestQueue(mContext.getApplicationContext());
          }
          return mRequestQueue;
      }
  
      public &lt;T&gt; void addToRequestQueue(Request&lt;T&gt; req) {
          getRequestQueue().add(req);
      }
  
      public ImageLoader getImageLoader() {
          return mImageLoader;
      }
  
  }
  </code></pre>
  
  <p>ListRowViewHolder.java:</p>
  
  <pre><code>public class ListRowViewHolder extends RecyclerView.ViewHolder {
  
      protected NetworkImageView thumbnail;
      protected NetworkImageView image_1;
      protected ImageButton yes;
      protected ImageButton no;
      protected TextView username;
      protected LinearLayout recLayout;
  
      public ListRowViewHolder(View view) {
          super(view);
          this.thumbnail = (NetworkImageView) view.findViewById(R.id.thumbnail);
          this.image_1 = (NetworkImageView) view.findViewById(R.id.image_1);
          this.yes = (ImageButton) view.findViewById(R.id.yesButton);
          this.no = (ImageButton) view.findViewById(R.id.noButton);
          this.username = (TextView) view.findViewById(R.id.pUsername);
          this.recLayout = (LinearLayout) view.findViewById(R.id.listItemLayout);
          view.setClickable(true);
      }
  
  }
  </code></pre>
  
  <p>FragmentHome.java:</p>
  
  <pre><code>public class FragmentHome extends Fragment {
  
      private final String postsUrl = "http://www.example.com/fetch_posts.php";
  
      private ProgressDialog progressDialog;
  
      private static final String TAG = "RecyclerViewExample";
      private List&lt;ListItems&gt; listItemsList = new ArrayList&lt;&gt;();
  
      private RecyclerView mRecyclerView;
      private MyRecyclerAdapter adapter;
  
      public FragmentHome() {
  
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          if (container == null) {
              return null;
          }
          View view = inflater.inflate(R.layout.fragment_home, container, false);
  
          mRecyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
  
          mRecyclerView.addItemDecoration(
                  new HorizontalDividerItemDecoration.Builder(getActivity())
                          .color(Color.BLACK)
                          .build());
  
          final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
          mRecyclerView.setLayoutManager(linearLayoutManager);
  
          updateFeed();
  
          return view;
      }
  
      public void updateFeed() {
          showPD();
  
          adapter = new MyRecyclerAdapter(getActivity(), listItemsList);
          mRecyclerView.setAdapter(adapter);
  
          RequestQueue request = Volley.newRequestQueue(getActivity());
  
          adapter.clearAdapter();
  
          JsonArrayRequest req = new JsonArrayRequest(postsUrl, new Response.Listener&lt;JSONArray&gt;() {
              @Override
              public void onResponse(JSONArray response) {
                  Log.d(TAG, response.toString());
  
                  try {
                      for (int i = 0; i &lt; response.length(); i++) {
                          JSONObject post = (JSONObject) response.get(i);
  
                          ListItems item = new ListItems();
                          item.setImage_1(post.getString("image_1"));
                          item.setUsername(post.getString("username"));
                          item.setProfilePicture(post.getString("image_1"));
                          listItemsList.add(item);
                      }
                  } catch (JSONException e) {
                      e.printStackTrace();
                      Toast.makeText(getActivity(), "Error: " + e.getMessage(), Toast.LENGTH_LONG).show();
                  }
                  adapter.notifyDataSetChanged();
                  hidePD();
              }
          }, new Response.ErrorListener() {
              @Override
              public void onErrorResponse(VolleyError error) {
                  VolleyLog.d(TAG, "Error: " + error.getMessage());
                  hidePD();
                  Toast.makeText(getActivity(), "Volley Error: " + error.getMessage(), Toast.LENGTH_LONG).show();
              }
          });
          request.add(req);
      }
  
      private void showPD() {
          if (progressDialog == null) {
              progressDialog = new ProgressDialog(getActivity());
              progressDialog.setMessage("Loading...");
              progressDialog.setCancelable(false);
              progressDialog.setCanceledOnTouchOutside(false);
              progressDialog.show();
          }
      }
  
      private void hidePD() {
          if (progressDialog != null) {
              progressDialog.dismiss();
              progressDialog = null;
          }
      }
  
      @Override
      public void onDestroy() {
          super.onDestroy();
          hidePD();
      }
  
  }
  </code></pre>