title: how to get clicks on two overlapping button in same frame layout in android
body: <p>i have two triangular shaped images that i want to use as button background.
  i used the frame layout to make overlapping and able to make a desired shape as in picture.</p>
  
  <p><img src="https://i.stack.imgur.com/ps06L.png" alt="its my final look"></p>
  
  <p>Now i just put onclick listener on each button but its not working properly only click on button two works every time.</p>
  
  <p>please help me to find solution.</p>
  
  <p>here is my code mainActivity.java code.</p>
  
  <pre><code>      package com.example.buttontest;
  
  import java.util.Locale;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.GestureDetector;
  import android.view.GestureDetector.OnGestureListener;
  import android.view.MotionEvent;
  import android.view.View;
  import android.view.View.OnTouchListener;
  import android.widget.Button;
  import android.widget.Toast;
  
  public class MainActivity extends Activity implements OnGestureListener{
      private GestureDetector gestureDetector;
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          gestureDetector=new GestureDetector(this);
  
          Button b1=(Button)findViewById(R.id.button2);
  
          Button b2=(Button)findViewById(R.id.button1);
  
          b1.setOnTouchListener(new OnTouchListener() {
  
              public boolean onTouch(View v, MotionEvent e) {
                  int width = findViewById(R.id.button1).getWidth();
                  int height = findViewById(R.id.button1).getHeight();
                  float touchedX = e.getX();
                  float touchedY = e.getY();
                  boolean inUpperTriangle = (height - touchedY) * width &gt; touchedX * height;
                  if(inUpperTriangle==true)
                      Toast.makeText(getApplicationContext(), "upper",Toast.LENGTH_SHORT).show();
  
                  if(inUpperTriangle) gestureDetector.onTouchEvent(e);
                  return inUpperTriangle;
              }
  
          });
  
          b2.setOnTouchListener(new OnTouchListener() {
  
              public boolean onTouch(View v, MotionEvent e) {
  
  
  
  
                  int width = findViewById(R.id.button2).getWidth();
                  int height = findViewById(R.id.button2).getHeight();
                  float touchedX = e.getX();
                  float touchedY = e.getY();
                  boolean inLowerTriangle = (height - touchedY) * width &lt; touchedX * height;
                  if(inLowerTriangle==true)
                      Toast.makeText(getApplicationContext(), "lower",Toast.LENGTH_SHORT).show();
                  if(inLowerTriangle) gestureDetector.onTouchEvent(e);
                  return inLowerTriangle;
              }
          });
  
  
  
  
      }
  
  
      public boolean onDown(MotionEvent e) {
          // TODO Auto-generated method stub
          return false;
      }
  
  
      public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
              float velocityY) {
          // TODO Auto-generated method stub
          return false;
      }
  
  
      public void onLongPress(MotionEvent e) {
          // TODO Auto-generated method stub
  
      }
  
  
      public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
              float distanceY) {
          // TODO Auto-generated method stub
          return false;
      }
  
  
      public void onShowPress(MotionEvent e) {
          // TODO Auto-generated method stub
  
      }
  
  
      public boolean onSingleTapUp(MotionEvent e) {
          return true;
      }
  
  }
  </code></pre>
  
  <p>and my layout file is.</p>
  
  <pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/FrameLayout1"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent" &gt;
  
  &lt;Button
      android:id="@+id/button2"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:background="@drawable/button2" /&gt;
  
  &lt;Button
      android:id="@+id/button1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:background="@drawable/button1" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>please let me know how to get correct clicks on both of these buttons.</p>
  
  <p>here are my drawables.i am using yellow triangle as button 1 image and green as button 2 image.
  <img src="https://i.stack.imgur.com/vfFIH.png" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/26ryY.png" alt="enter image description here"></p>