title: [android]How to implement Jess Ander's TwoWayGridView?
body: <p>I am trying to dynamically add image buttons on the click of a button. When the number of image button exceeds the screen width, I should be able to horizontally scroll. I tried to implement <a href="https://github.com/jess-anders/two-way-gridview" rel="nofollow">Jess-Ander's TwoWayGridView</a> but with no success. I am a beginner. So please bear with me if the mistake is too elementary.</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="match_parent"
  android:orientation="vertical"
  tools:context=".MainActivity" &gt;
  
  &lt;Button
      android:id="@+id/button1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:onClick="onClick"
      android:text="Button" /&gt;
  
  &lt;com.jess.ui.TwoWayGridView
  
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:background="#E8E8E8"
  android:id="@+id/gridview"
  android:layout_width="fill_parent" 
  android:layout_height="fill_parent"
  app:cacheColorHint="#E8E8E8"
  app:columnWidth="80dp"
  app:rowHeight="80dp"
  app:numColumns="auto_fit"
  app:numRows="2"
  app:verticalSpacing="16dp"
  app:horizontalSpacing="16dp"
  app:stretchMode="spacingWidthUniform"
  app:scrollDirectionPortrait="vertical"
  app:scrollDirectionLandscape="horizontal"
  app:gravity="center"&gt;
  
  &lt;LinearLayout
      android:id="@+id/linearLayout1"
      android:orientation="horizontal"
      android:layout_width="match_parent"
      android:layout_height="match_parent" /&gt;
  &lt;/com.jess.ui.TwoWayGridView&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>and here's the code:</p>
  
  <pre><code>package com.example.dynamic;
  
  
  import android.os.Bundle;
  import android.app.Activity;
  import android.view.View;
  import android.widget.ImageView;
  import android.widget.LinearLayout;
  
  
  public class MainActivity extends Activity {
  
      LinearLayout linearLayout1;
  
  
  
  
  @Override
  public void onCreate(Bundle bundle) {
      super.onCreate(bundle);
      setContentView(R.layout.activity_main);
      linearLayout1 = (LinearLayout) findViewById(R.id.linearLayout1);
  
  
  
  }
  
  public void onClick(View v){
  
      ImageView image = new ImageView(MainActivity.this);
      image.setBackgroundResource(R.drawable.ic_launcher);
      linearLayout1.addView(image);        
  
  }
  
  
  
  }
  </code></pre>