title: Horizontal scrolling in android gridview
body: <p>I have a grid view in my application and i need to scroll it horizontally.I have tried changing the gridview to gallery.But then only one row is available,but i need different rows as in a grid view.So basically what i need is a gridview that can be scrolled horizontally.Is there any efficient way to do this?Thanks in advance.</p>
  
  <p>Regards 
  Anu</p>
  
  <p>Hi,Thanks for the reply.i have tried using a Gallery and implement an adapter that provides a multirow view in its getView method.</p>
  
  <p>My java file is:</p>
  
  <pre><code>public class Gridview extends Activity 
  {
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      Gallery g = (Gallery) findViewById(R.id.gallery);
      g.setAdapter(new GridAdapter(this));
  
      g.setOnItemClickListener(new OnItemClickListener() {
          public void onItemClick(AdapterView parent, View v, int position, long id) {
              Toast.makeText(Gridview.this, "" + position, Toast.LENGTH_SHORT).show();
          }
      });
  }
  
  public class GridAdapter extends BaseAdapter {
      int mGalleryItemBackground;
      private Context mContext;
  
      private Integer[] mImageIds = {
              R.drawable.icon,
              R.drawable.icon,
              R.drawable.icon,
              R.drawable.icon,
              R.drawable.icon,
              R.drawable.icon,
              R.drawable.icon,
      };
  
      public GridAdapter(Context c) {
          mContext = c;
          TypedArray a = obtainStyledAttributes(R.styleable.HelloGallery);
          mGalleryItemBackground = a.getResourceId(
                  R.styleable.HelloGallery_android_galleryItemBackground, 0);
          a.recycle();
      }
  
      public int getCount() {
          return mImageIds.length;
      }
  
      public Object getItem(int position) {
          return position;
      }
  
      public long getItemId(int position) {
          return position;
      }
  
      public View getView(int position, View convertView, ViewGroup parent) {
  
        View v;
         if(convertView==null)
         {
         LayoutInflater li = getLayoutInflater();
         v = li.inflate(R.layout.icon, null);  
  
         ImageView iv = (ImageView)v.findViewById(R.id.icon_image);
         iv.setImageResource(R.drawable.icon);    
  
         }
         else
         {
         v = convertView;
         }
        return v;
      }
  }
  }
  </code></pre>
  
  <p>main.xml is :</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt;
   &lt;Gallery xmlns:android="http://schemas.android.com/apk/res/android" 
   android:id="@+id/gallery"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"/&gt;
  </code></pre>
  
  <p>icon.xml is:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/linearlayout"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"&gt;
  
   &lt;ImageView
   android:id="@+id/icon_image"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:orientation="vertical"&gt;
   &lt;/ImageView&gt;
  
   &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>The output i got is : <a href="http://www.4shared.com/photo/MzUcmzel/device.html">http://www.4shared.com/photo/MzUcmzel/device.html</a></p>
  
  <p>But this is not i need actually.i want the icons in different rows.Any help is appreciated.</p>