title: Android : How to embed a custom view into a constraint layout?
body: <p>I have a custom view with animation and I need to somehow get it in the constraint layout. <a href="https://gyazo.com/dce6b1a8922792f3f1851fcfee9fb058" rel="nofollow noreferrer">Here</a> is a little example of what I mean. I basically need a small area where I can use custom animations/bitmaps and all that stuff.</p>
  
  <p>So far I've only managed to apply the view on all the screen with:
  setContentView(customView).</p>
  
  <p><strong>customView:</strong></p>
  
  <pre><code>public class CrashView extends View {
  
  private int width, height,bheight, bwidth, boxwidth, boxheight;
  private float x,y,vx,vy;
  
  private Bitmap bullet;
  private Paint AA = new Paint(Paint.ANTI_ALIAS_FLAG);
  
  public CrashView (Context context){
      super(context);
  
      Display display = ((Activity) getContext()).getWindowManager().getDefaultDisplay();
      Point size = new Point();
      display.getSize(size);
  
      bullet = BitmapFactory.decodeResource(getResources(), R.drawable.bullet);
      bullet = Bitmap.createScaledBitmap(bullet, bullet.getWidth()/5, bullet.getHeight()/5, true);
  
      width = size.x;
      height = size.y;
  
      bheight = bullet.getHeight();
      bwidth = bullet.getWidth();
  
      boxheight = height / 4;
      boxwidth = (width / 20) * 19;
  
      x = (width/20)/4;
      y = boxheight-bheight/4*3;
  }
  
  @Override
  protected void onDraw(Canvas canvas) {
      super.onDraw(canvas);
  
      vy = -0.1f - (float) ((Math.pow(x / 600, 2)) / 1.25);
  
      x += vx;
      y += vy;
  
      canvas.drawBitmap(bullet, x, y, AA);
      invalidate();
  }
  </code></pre>