title: Create Buttons on Canvas in Android
body: <p>I have a problem, I don't know how to create buttons on my canvas. This code below I wrote to draw a line on a picture. Then I want to add some buttons on that picture. Hope you guys can help me.</p>
  
  <pre><code>public class DrawShape extends Activity implements View.OnTouchListener {
  ImageView imagTest;
  Bitmap bitmap;
  Canvas canvas;
  Paint paint;
  Button abc;
  float downX, downY, moveX, moveY, upX, upY = 0;
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.drawshape);
  
      imagTest = (ImageView) findViewById(R.id.imgTest);//Add image 
  
      Display display = getWindowManager().getDefaultDisplay();
      int dw = display.getWidth();
      int dh = display.getHeight();
  
      Bitmap loadedBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.image1);//load image onto bitmap
      Bitmap scaledloadedBitmap = Bitmap.createScaledBitmap(loadedBitmap, dw, dh, false);
      Bitmap drawableBitmap = scaledloadedBitmap.copy(Bitmap.Config.ARGB_8888, true);
      Matrix matrix = new Matrix();
      imagTest.setScaleType(ImageView.ScaleType.MATRIX);
      matrix.postRotate(90);
  
      canvas = new Canvas(drawableBitmap);
      paint = new Paint();
      paint.setColor(Color.GREEN);
      paint.setShadowLayer(5, 2, 2, Color.BLUE);
      paint.setStrokeWidth(10);
      imagTest.setImageBitmap(drawableBitmap);
      imagTest.setOnTouchListener(this);
  
  
  }
  @Override
  public boolean onTouch(View v, MotionEvent event) {
      switch (event.getAction()) {
          case MotionEvent.ACTION_DOWN:
              downX = event.getX();
              downY = event.getY();
              break;
          case MotionEvent.ACTION_MOVE:
              moveX = event.getX();
              moveY = event.getY();
  
              break;
          case MotionEvent.ACTION_UP:
              upX = event.getX();
              upY = event.getY();
              canvas.drawLine(downX, downY, upX, upY, paint);//Handle when touch up
              imagTest.invalidate();
              break;
      }
      return true;
  }
  }
  </code></pre>