title: Android level select with custom gallery
body: <p>I need to make level select for game , I used custom gallery. (are there any better way to do it)
  My images are in PNG format and gallery scroll very slowly 
  what  I have to change to work it better? </p>
  
  <p>my code:</p>
  
  <pre><code>public class LevelSelectActivity extends Activity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      setContentView(R.layout.level);
  
      ImageButton back = (ImageButton) findViewById(R.id.back);
      back.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              LevelSelectActivity.this.finish();
          }
      });
  
      Gallery levels = (Gallery) findViewById(R.id.levels);
      levels.setAdapter(new ImageAdapter(this));
  
  
  }
  
  public class ImageAdapter extends BaseAdapter {
      /** The parent context */
      private Context myContext;
  
      private int[] myImageIds = { R.drawable.level_select_1, R.drawable.level_select_2,
              R.drawable.level_select_3, R.drawable.level_select_4, R.drawable.level_select_5 };
  
      /** Simple Constructor saving the 'parent' context. */
      public ImageAdapter(Context c) {
          this.myContext = c;
      }
  
      /** Returns the amount of images we have defined. */
      public int getCount() {
          return this.myImageIds.length;
      }
  
      /* Use the array-Positions as unique IDs */
      public Object getItem(int position) {
          return position;
      }
  
      public long getItemId(int position) {
          return position;
      }
  
      /**
       * Returns a new ImageView to be displayed, depending on the position
       * passed.
       */
      public View getView(int position, View convertView, ViewGroup parent) {
          ImageView i = null;
  
          if (convertView == null) {
  
              i = new ImageView(this.myContext);
  
              i.setBackgroundResource(this.myImageIds[position]);
  
              i.setScaleType(ImageView.ScaleType.FIT_XY);
  
              i.setLayoutParams(new Gallery.LayoutParams(LayoutParams.FILL_PARENT,
                      LayoutParams.FILL_PARENT));
  
          } else {
  
              i = (ImageView) convertView;
  
          }
  
          return i;
      }
  }
  </code></pre>
  
  <p>}</p>