title: How to scale activity to fit the no of images exactly without any space
body: <p>I'm facing a very strange problem. Here I have total 8 images in Gridview Style where each image is exactly 392×500 Size. But when I run app, There is alwayas a small space left  below the last 8th image.</p>
  
  <p>Here is my code </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>public class BooksPage extends AppCompatActivity
          implements NavigationView.OnNavigationItemSelectedListener {
  
  
      int images[] = {R.drawable.phy,R.drawable.chem,R.drawable.drawable_logy,R.drawable.drawable_geology,R.drawable.bbs,R.drawable.drawable_chartered,R.drawable.bachelor,R.drawable.bachelor};
  
      String stream[]= {"MSC Physics","MSC Chemistry","MSC Biology",
              "MSC Geology","BBS|BBA","CA","Bachelor","+2 Science"};
      TextView navName,navEmail;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_books_page);
          Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
          setSupportActionBar(toolbar);
          getSupportActionBar().setTitle("पुस्तक किनबेच");
  
          DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
          ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                  this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
          drawer.setDrawerListener(toggle);
          toggle.syncState();
  
          NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
          View navHeaderView = navigationView.getHeaderView(0);
          navName = (TextView)navHeaderView.findViewById(R.id.nav_name);
          navEmail = (TextView)navHeaderView.findViewById(R.id.nav_mail);
  
          navigationView.setNavigationItemSelectedListener(this);
  
          RecyclerView favPlaces = (RecyclerView) findViewById(R.id.favPlaces);
          StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL);
          layoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_NONE);
          favPlaces.setLayoutManager(layoutManager);
          favPlaces.setHasFixedSize(true);
          ArrayList&lt;BookDetails&gt; placeList = getPlaces();
  
          if (!isNetworkStatusAvialable(this)) {
  
  
              Toast.makeText(this, "No Internet!", Toast.LENGTH_SHORT).show();
  
  
  
          }
  
          StaggeredAdapter staggeredAdapter = new StaggeredAdapter(this,placeList);
          favPlaces.setAdapter(staggeredAdapter);
          navName.setText(PreferenceManager.getDefaultSharedPreferences(this).getString("name","null"));
          navEmail.setText(PreferenceManager.getDefaultSharedPreferences(this).getString("email","null"));
      }
      private ArrayList&lt;BookDetails&gt; getPlaces() {
          ArrayList&lt;BookDetails&gt; details = new ArrayList&lt;&gt;();
          for (int index=0; index&lt;images.length;index++){
              details.add(new BookDetails(images[index],stream[index]));
          }
          return details;
      }
  
     
  
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>My xml code of adapter is </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout 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:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"&gt;
  
      &lt;android.support.v7.widget.CardView
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          app:cardUseCompatPadding="true"
          app:cardCornerRadius="4dp"&gt;
          &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical"
              android:background="@color/colorPrimaryDark"&gt;
  
              &lt;ImageView
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:id="@+id/placePic"
                  android:adjustViewBounds="true"
                  android:scaleType="fitXY" /&gt;
  
              &lt;TextView
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:id="@+id/placeName"
                  android:textStyle="bold"
                  android:textColor="#ffffff"
                  android:fontFamily="sans-serif-condensed"
                  android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
                  android:gravity="center"
                  android:textSize="16sp"/&gt;
  
  
          &lt;/LinearLayout&gt;
      &lt;/android.support.v7.widget.CardView&gt;
  
  &lt;/LinearLayout&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Then I though maybeincrease in size of images will do the trick but whether I make the image size 50×50 or 1000×1000, The image is always same size and space is also constant.</p>
  
  <p>Here is the screenshot
  <a href="https://i.stack.imgur.com/7MWKX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7MWKX.png" alt="enter image description here"></a></p>
  
  <p>and again same with another image
  [![enter image description here][2]][2]</p>
  
  <p>But funny  part is  when I use the same image of 7th poition in 8th position also.....Then space disappers and images fit exactly.</p>
  
  <p>Here is the screenshot
  <a href="https://i.stack.imgur.com/Mr0Jp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Mr0Jp.png" alt="enter image description here"></a></p>
  
  <p>what is the problem here? How can I fix it any help is appreciated</p>
  
  <p>I'm using photoshop to change width and height of  my Images by Saving for 
  Web.</p>