title: Android - How to click through transparent area of custom view
body: <p>In order to position a button in the exact spot on all devices, I have created it with a custom view. The button takes up a small part of the screen but the actual view takes up most of the screen. All the area around the button is transparent. How can I allow the user to click through the transparent area to buttons underneath but still click the button area on the view?</p>
  
  <p>Here is the relavant code:</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
  final float dotScale = 0.3f;
  Dot dot1, dot2;
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);
  
  RelativeLayout myLayout = (RelativeLayout) findViewById(R.id.mainView);
  MyView myView = new MyView(this);
  myLayout.addView(myView);
  
  // Two dots are created.
  
  dot1 = new Dot(this);
  dot1.xOffset = 2.9f;
  dot1.yOffset = 3.3f;
  myLayout.addView(dot1);
  dot2 = new Dot(this);
  dot2.xOffset = -2.4f;
  dot2.yOffset = 1.1f;
  myLayout.addView(dot2);
  
  // Makes dots clickable
  
  dot1.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
          if (!dot1.isClicked) {
              dot1.animate().setDuration(300).setInterpolator(new AnticipateInterpolator())
                      .scaleXBy(dotScale).scaleYBy(dotScale).alpha(1.0f);
              dot1.isClicked = true;
          }
      }
  });
  
  dot2.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
          if (!dot2.isClicked) {
              dot2.animate().setDuration(300).setInterpolator(new AnticipateInterpolator())
                      .scaleXBy(dotScale).scaleYBy(dotScale).alpha(1.0f);
              dot2.isClicked = true;
          }
      }
  });
  
  }
  
  .......
  
  //custom view for Dots
  
  class Dot extends View {
  
  int radius;
  float xOffset;
  float yOffset;
  boolean isClicked = false;
  
  public Dot(Context context) {
      super(context);
      setClickable(true);
  
  
  }
  
  @Override
  protected void onDraw(Canvas canvas) {
      super.onDraw(canvas);
  
      int x = getWidth();
      int y = getHeight();
      double ratio = (547d / 828d);
      float circleX = (float)((x / 2) - (y * ratio) / xOffset);
      float circleY = (float)(y / yOffset);
  
      radius = (int)((float)y/13);
      setPivotX(circleX);
      setPivotY(circleY);
  
      Paint paint = new Paint();
      paint.setColor(Color.RED);
      canvas.drawCircle(circleX, circleY, radius, paint);
  }
  
  
  }
  </code></pre>