title: GridView with image and text on center
body: <p>Hi I want develop this type of layout but i am confused that is it the gridview or imageviews aligned like that .
  Well my question is how can i acheive this type of menu in my fragment in which i am working </p>
  
  <p><a href="https://i.stack.imgur.com/rR1Lb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rR1Lb.png" alt="enter image description here"></a></p>
  
  <p>After Implementing Gridview from <a href="https://www.learn2crack.com/2014/01/android-custom-gridview.html" rel="nofollow noreferrer">https://www.learn2crack.com/2014/01/android-custom-gridview.html</a></p>
  
  <p>i got this like screen </p>
  
  <p><a href="https://i.stack.imgur.com/3IOqB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3IOqB.png" alt="enter image description here"></a></p>
  
  <p>how can i make the gridView look like at first image ?</p>
  
  <p>as the text on the center of the block i really want to achieve it .</p>
  
  <p><strong>grid_single.xml</strong></p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      android:padding="5dp" &gt;
  
      &lt;ImageView
          android:id="@+id/grid_image"
          android:layout_width="match_parent"
          android:src="@drawable/denist_3"
          android:layout_height="50dp"&gt;
      &lt;/ImageView&gt;
  
      &lt;TextView
          android:id="@+id/grid_text"
  
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginTop="15dp"
          android:layout_gravity="center"
          android:text="Dentist"
          android:textSize="9sp" &gt;
      &lt;/TextView&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>main_act.xml:</strong></p>
  
  <pre><code>&lt;RelativeLayout
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"&gt;
         &lt;GridView
          android:numColumns="auto_fit"
          android:layout_below="@+id/comsp"
          android:gravity="center"
          android:columnWidth="150dp"
          android:stretchMode="columnWidth"
          android:layout_width="fill_parent"
          android:layout_height="600dp"
          android:id="@+id/grid"
          /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p><strong>Adapterclass.java</strong></p>
  
  <pre><code>public class CustomGrid extends BaseAdapter{
      private Context mContext;
      private final String[] web;
      private final int[] Imageid;
  
      public CustomGrid(Context c,String[] web,int[] Imageid ) {
          mContext = c;
          this.Imageid = Imageid;
          this.web = web;
      }
  
      @Override
      public int getCount() {
          // TODO Auto-generated method stub
          return web.length;
      }
  
      @Override
      public Object getItem(int position) {
          // TODO Auto-generated method stub
          return null;
      }
  
      @Override
      public long getItemId(int position) {
          // TODO Auto-generated method stub
          return 0;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          // TODO Auto-generated method stub
          View grid;
          LayoutInflater inflater = (LayoutInflater) mContext
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
          if (convertView == null) {
  
              grid = new View(mContext);
              grid = inflater.inflate(R.layout.grid_single, null);
              TextView textView = (TextView) grid.findViewById(R.id.grid_text);
              ImageView imageView = (ImageView)grid.findViewById(R.id.grid_image);
              textView.setText(web[position]);
              imageView.setImageResource(Imageid[position]);
          } else {
              grid = (View) convertView;
          }
  
          return grid;
      }
  }
  </code></pre>
  
  <p><strong>Mainactivity.java</strong></p>
  
  <pre><code>     CustomGrid adapter = new CustomGrid(getActivity(), web, imageId);
  
   grid=(GridView)v.findViewById(R.id.grid);
   grid.setAdapter(adapter);
          grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                                      int position, long id) {
                  Toast.makeText(getActivity(), "You Clicked at " +web[+ position], Toast.LENGTH_SHORT).show();
  
              }
          });
  </code></pre>