title: Android GridView not showing any images
body: <p>I have followed the example at <a href="https://developer.android.com/guide/topics/ui/layout/gridview.html" rel="nofollow noreferrer">https://developer.android.com/guide/topics/ui/layout/gridview.html</a> and used other resources on SO to make it at least not crash given I'm using the grid view in a fragment.</p>
  
  <p>I'm trying to just get a list of images to show in the grid view (for simplicity I've just put the same image twice in <code>mThumbIds</code> in <code>ImageAdapter</code>).</p>
  
  <p>But when I run the app, no GridView at all is showing in the fragment. Other views in the fragment load fine, but it's like the gridview isn't even there. I'm not really sure how to debug this.</p>
  
  <p>Any help is appreciated, thanks.</p>
  
  <p>ImageAdapter.java:</p>
  
  <pre><code>import android.content.Context;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.BaseAdapter;
  import android.widget.GridView;
  import android.widget.ImageView;
  
  public class ImageAdapter extends BaseAdapter {
      private Context mContext;
  
      public ImageAdapter(Context c) {
          mContext = c;
      }
  
      public int getCount() {
          return mThumbIds.length;
      }
  
      public Object getItem(int position) {
          return null;
      }
  
      public long getItemId(int position) {
          return 0;
      }
  
      // create a new ImageView for each item referenced by the Adapter
      public View getView(int position, View convertView, ViewGroup parent) {
          ImageView imageView;
          if (convertView == null) {
              // if it's not recycled, initialize some attributes
              imageView = new ImageView(mContext);
              imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
              imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
              imageView.setPadding(8, 8, 8, 8);
          } else {
              imageView = (ImageView) convertView;
          }
  
          imageView.setImageResource(mThumbIds[position]);
          return imageView;
      }
  
      // references to our images
      private Integer[] mThumbIds = {
          R.drawable.placeholder, R.drawable.placeholder
      };
  }
  </code></pre>
  
  <p>PlaceholderFragment:</p>
  
  <pre><code>public static class PlaceholderFragment extends Fragment
  {
  
  ...
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
      {
          View rootView = inflater.inflate(R.layout.fragment_items, container, false);
          TextView textView = (TextView) rootView.findViewById(R.id.items_subheading);
          textView.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER)));
  
          GridView allImages = (GridView) rootView.findViewById(R.id.items_all_images);
          allImages.setAdapter(new ImageAdapter(rootView.getContext()));
  
          allImages.setOnItemClickListener(new AdapterView.OnItemClickListener() {
              public void onItemClick(AdapterView&lt;?&gt; parent, View v, int position, long id)
              {
                  // empty
              }
          });
  
          return rootView;
      }
  </code></pre>
  
  <p>fragment_items.xml</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context="com.example.myapp.ItemsActivity$PlaceholderFragment"&gt;
  
  &lt;LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="horizontal" &gt;
  
      &lt;LinearLayout
          android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:layout_weight="2"
          android:gravity="top|left"
          android:orientation="vertical"&gt;
  
          &lt;ImageView
              android:id="@+id/items_image"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:src="@drawable/placeholder"
              android:scaleType="fitStart"
              style="@style/ItemsImage" /&gt;
  
          &lt;GridView
              android:id="@+id/items_all_images"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:columnWidth="20dp"
              android:numColumns="auto_fit"
              android:verticalSpacing="10dp"
              android:horizontalSpacing="10dp"
              android:gravity="center"
              android:background="#000000"
              /&gt;
  
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout
          android:layout_width="0dp"
          android:layout_height="match_parent"
          android:layout_weight="3"
          android:orientation="vertical"
          android:background="@drawable/items_border"&gt;
  
          &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical"&gt;
  
              &lt;!-- About 10 text views --&gt;
  
          &lt;/LinearLayout&gt;
  
  
      &lt;/LinearLayout&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p></p>
  
  <h2>Edit</h2>
  
  <p>Aiming for:</p>
  
  <p><a href="https://i.stack.imgur.com/ieo5V.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ieo5V.png" alt="enter image description here"></a></p>
  
  <h2>Edit 2</h2>
  
  <p>Solution: Figured it out! Needed <code>android:adjustViewBounds="true"</code> on the <code>ImageView</code>. Without that attribute it seemed to be taking unlimited space below its position.</p>