title: Layering images in Android Studio?
body: <p>Currently I have a UI designed with imageviews, the problem is they cannot overlap or be layered. (Or if they can, I haven't figure out how) 
  I'd like to do 3 layers, the bottom layer is the board,<br>
  The next layer is pieces, 
  The next layer is a selected piece with valid moves. </p>
  
  <p>My idea is that I will have listeners on the top layer only. </p>
  
  <p>I am just looking for the best data structure to use for this, the app is a chesslike game I am working on developing. </p>
  
  <p>If there is another approach that might be better I am all ears as well. </p>
  
  <p>Thanks!</p>
  
  <p>As requested code : </p>
  
  <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical" android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:weightSum="1"&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Game Activity"
          android:id="@+id/textView5"
          android:layout_gravity="center_horizontal"
          android:layout_alignParentTop="true"
          android:layout_centerHorizontal="true" /&gt;
  
      &lt;ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/imageView22"
          android:src="@drawable/ni_whitesquare"
          android:layout_below="@+id/textView5"
          android:layout_alignRight="@+id/textView5"
          android:layout_alignEnd="@+id/textView5"
          android:layout_marginRight="15dp"
          android:layout_marginEnd="15dp"
          android:layout_marginTop="76dp"
          android:contentDescription="whitesquare"
          android:clickable="true" /&gt;
  
      &lt;ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/imageView32"
          android:src="@drawable/ni_blacksquare"
          android:layout_alignTop="@+id/imageView22"
          android:layout_alignLeft="@+id/imageView22"
          android:layout_alignStart="@+id/imageView22"
          android:layout_marginLeft="23dp"
          android:layout_marginStart="23dp"
          android:contentDescription="blacksquare"
          android:clickable="true" /&gt;
  
      &lt;ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/imageView12"
          android:src="@drawable/ni_blacksquare"
          android:contentDescription="blacksquare"
          android:clickable="true"
          android:layout_alignTop="@+id/imageView22"
          android:layout_toLeftOf="@+id/imageView22"
          android:layout_toStartOf="@+id/imageView22" /&gt;
  
      &lt;ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/imageView21"
          android:src="@drawable/ni_blacksquare"
          android:contentDescription="blacksquare"
          android:clickable="true"
          android:layout_below="@+id/imageView22"
          android:layout_toRightOf="@+id/imageView12"
          android:layout_toEndOf="@+id/imageView12" /&gt;
  
      &lt;ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/imageView23"
          android:src="@drawable/ni_blacksquare"
          android:contentDescription="blacksquare"
          android:clickable="true"
          android:layout_above="@+id/imageView12"
          android:layout_toLeftOf="@+id/imageView33"
          android:layout_toStartOf="@+id/imageView33" /&gt;
  
      &lt;ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/imageView31"
          android:src="@drawable/ni_whitesquare"
          android:contentDescription="whitesquare"
          android:clickable="true"
          android:layout_alignBottom="@+id/imageView21"
          android:layout_alignLeft="@+id/imageView32"
          android:layout_alignStart="@+id/imageView32" /&gt;
  
      &lt;ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/imageView11"
          android:src="@drawable/ni_whitesquare"
          android:contentDescription="whitesquare"
          android:clickable="true"
          android:layout_alignTop="@+id/imageView21"
          android:layout_toLeftOf="@+id/imageView21"
          android:layout_toStartOf="@+id/imageView21" /&gt;
  
      &lt;ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/imageView13"
          android:src="@drawable/ni_whitesquare"
          android:contentDescription="whitesquare"
          android:clickable="true"
          android:layout_alignTop="@+id/imageView23"
          android:layout_alignLeft="@+id/imageView12"
          android:layout_alignStart="@+id/imageView12" /&gt;
  
      &lt;ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/imageView33"
          android:src="@drawable/ni_whitesquare"
          android:contentDescription="whitesquare"
          android:clickable="true"
          android:layout_alignTop="@+id/imageView23"
          android:layout_alignLeft="@+id/imageView32"
          android:layout_alignStart="@+id/imageView32" /&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceSmall"
          android:text="@string/directions"
          android:id="@+id/directionsstring"
          android:layout_marginTop="30dp"
          android:layout_below="@+id/imageView21"
          android:layout_alignLeft="@+id/textView5"
          android:layout_alignStart="@+id/textView5" /&gt;
  
      &lt;ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/Startingpoint"
          android:src="@drawable/ni_pawn"
          android:layout_above="@+id/imageView11"
          android:layout_toLeftOf="@+id/imageView12"
          android:layout_toStartOf="@+id/imageView12" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Activity : </p>
  
  <pre><code>public class GameActivity extends Activity
  
  {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_game);
          final ImageView mStarting = (ImageView) findViewById(R.id.Startingpoint);
  
          final ImageView mCenterSq = (ImageView) findViewById(R.id.imageView22);
          final ImageView m12 = (ImageView)findViewById(R.id.imageView12);
  
  
          mCenterSq.setOnClickListener(new View.OnClickListener() {
              @Override
  
              public void onClick(View v)
              {
                  m12.setImageResource(R.drawable.ni_blacksquare);
                  mCenterSq.setImageResource(R.drawable.ni_portal);
                  //center square turns into a portal when clicked.
                  if (mStarting.getDrawable().getConstantState().equals(getResources().getDrawable(R.drawable.ni_whitesquare).getConstantState()) &amp;&amp;
                          mCenterSq.getDrawable().getConstantState().equals(getResources().getDrawable(R.drawable.ni_portal).getConstantState()) )
                  {
                      mCenterSq.setOnClickListener(null);
                      return;
                  }
  
  
  
                  mStarting.setOnClickListener(new View.OnClickListener()  {
                  @Override
                  public void onClick(View v)
                  {
  
                      //Pawn selected
                      mStarting.setImageResource(R.drawable.ni_whitesquare);
                      m12.setImageResource(R.drawable.ni_greensquare);
                      mCenterSq.setImageResource(R.drawable.ni_greensquare);
                      if (mStarting.getDrawable().getConstantState().equals(getResources().getDrawable(R.drawable.ni_whitesquare).getConstantState()))
                      {
                          mStarting.setOnClickListener(null);
                      }
  
  
                      m12.setOnClickListener(new View.OnClickListener() {
  
                          @Override
                          public void onClick(View v)
  
                          {
                              if (m12.getDrawable().getConstantState().equals(getResources().getDrawable(R.drawable.ni_greensquare).getConstantState()))
                              {
                                  m12.setImageResource(R.drawable.ni_pawn);
                                  mCenterSq.setImageResource(R.drawable.ni_portal);
                              }
  
  
                          }
  
                      });
                      }
  
  
  
  
  
  
                       });
  
  
              };
          });
  
      }
  }
  </code></pre>