title: how to click on bitmapdrawable from the canvas
body: <p>i  have image(ball) this of type BitmapDrawable and it moves all directions on the screen for that i am taking ondraw(canvas) in animatedview.java its fine . my requirement is i want click on that image only but unfortunately the total screen acts as a event.so plese help me, how to click on that image only so that i am proceeding farther development.i will drop my total code here</p>
  
  <pre><code>MainActivity
  
  public class MainActivity extends Activity {
  
      Context context;
      int count=0;
      EditText text;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          AnimatedView animatedView=(AnimatedView) findViewById(R.id.anim_view);
          animatedView.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  EditText text=(EditText) findViewById(R.id.editText1);
  
                  ImageView imageView=(ImageView) findViewById(R.drawable.ball);
                   v.startAnimation(AnimationUtils.loadAnimation(MainActivity.this, R.anim.animation));
  
  
              }
          });
  
  animatedview.java:
  
  public class AnimatedView extends ImageView{
  
      private Context mContext;
      int x = -1;
      int y = -1;
      private int xVelocity = 10;
      private int yVelocity = 5;
      private Handler h;
      private final int FRAME_RATE = 30;
      BitmapDrawable ball;
  
      public AnimatedView(Context context, AttributeSet attrs)  {  
          super(context, attrs);  
          mContext = context;  
          h = new Handler();
      } 
  
      private Runnable r = new Runnable() {
          @Override
          public void run() {
              invalidate(); 
          }
      };
  
      @Override
      protected void onDraw(Canvas c) {  
  
          BitmapDrawable ball = (BitmapDrawable) mContext.getResources().getDrawable(R.drawable.ball);  
          if (x&lt;0 &amp;&amp; y &lt;0) {
              x = this.getWidth()/2;
              y = this.getHeight()/2;
          } else {
              x += xVelocity;
              y += yVelocity;
              if ((x &gt; this.getWidth() - ball.getBitmap().getWidth()) || (x &lt; 0)) {
                  xVelocity = xVelocity*-1;
              }
              if ((y &gt; this.getHeight() - ball.getBitmap().getHeight()) || (y &lt; 0)) {
                  yVelocity = yVelocity*-1;
              }
          }
          c.drawBitmap(ball.getBitmap(), x, y, null);  
  
          h.postDelayed(r, FRAME_RATE);    
  
      }
  
  
  main.xml
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical"
      android:background="#000000"&gt;
  
  &lt;com.example.example.AnimatedView
          android:id="@+id/anim_view"
          android:layout_width="fill_parent"
          android:layout_height="420dp"
          android:onClick="imageClicked" /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>