title: Android - Center image inside adapter
body: <p>I want my <strong>ImageView</strong> and <strong>TextView</strong> to be centred within my <strong>ViewHolder</strong>.</p>
  
  <p><em>Visual representation of what it looks like at the moment when I click on it:</em></p>
  
  <p><a href="https://i.stack.imgur.com/pPGEM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pPGEM.png" alt="Visual representation of what it looks like"></a></p>
  
  <p>It is pushed to the left, so when I click it, it 'highlights' right of the imageview as well.</p>
  
  <p><strong>ImageAdapter.java</strong></p>
  
  <pre><code>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(final int position, View convertView, ViewGroup parent) {
  
          LayoutInflater inflater = LayoutInflater.from(mContext);
          final ViewHolder holder;
  
          if (convertView == null) { // if it's not recycled, initialize some
              // attributes
              convertView = inflater.inflate(R.layout.item_level_single, null, true);
              holder = new ViewHolder();
              holder.image = (ImageView) convertView
                      .findViewById(R.id.myImageView);
  
              holder.number = (TextView) convertView
                      .findViewById(R.id.myImageViewText);
              convertView.setTag(holder);
  
          } else {
              holder = (ViewHolder) convertView.getTag();
          }
  
          holder.image.setImageResource(mThumbIds[position]);
          if (position == 0){
              holder.number.setText("1");
          }if (position == 1){
              holder.number.setText("2");
          }if (position == 2){
              holder.number.setText("3");
          }if (position == 3){
              holder.number.setText("4");
          }if (position == 4){
              holder.number.setText("5");
          }if (position == 5){
              holder.number.setText("6");
          }if (position == 6){
              holder.number.setText("7");
          }if (position == 7){
              holder.number.setText("8");
          }if (position == 8){
              holder.number.setText("9");
          }
  
  
  
          return convertView;
      }
  
      // references to our images
      private Integer[] mThumbIds = {
  
              R.drawable.ic_round, R.drawable.ic_round,
              R.drawable.ic_round, R.drawable.ic_round,
              R.drawable.ic_round, R.drawable.ic_round,
              R.drawable.ic_round, R.drawable.ic_round,
              R.drawable.ic_round,
  
      };
  
  
      private static class ViewHolder{
          public ImageView image;
          public TextView number;
  
      }
  
  }
  </code></pre>
  
  <p><strong>item_single.xml</strong></p>
  
  <pre><code>    &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_centerInParent="true"
      android:id="@+id/single"
       &gt;
  
      &lt;ImageView
          android:id="@+id/myImageView"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/ic_oval_big_white"
          /&gt;
  
      &lt;TextView
          android:id="@+id/myImageViewText"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignLeft="@+id/myImageView"
          android:layout_alignTop="@+id/myImageView"
          android:layout_alignRight="@+id/myImageView"
          android:layout_alignBottom="@+id/myImageView"
          android:gravity="center"
          android:text="1"
          android:textColor="#000000" /&gt;
  
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>EDIT - added item_single.xml</p>