title: How to prevent custom shape from pushing out of the LinearLayout?
body: <p>I have a Custom View that extends RelativeLayout with overridden onDraw() method so that it looks like a message bubble. This View is in the LinearLayout. When I try to fill this custom View with content, part of its shape is pushed out of the LinearLayout. How to prevent this behaviour?How to prevent this behaviour?</p>
  
  <p><a href="https://i.stack.imgur.com/gu1kv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gu1kv.png" alt="enter image description here"></a></p>
  
  <pre><code>&lt;LinearLayout
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"&gt;
  
      &lt;View
          android:layout_width="0dp"
          android:layout_height="0dp"
          android:layout_weight="1" /&gt;
  
      &lt;TextView
          android:id="@+id/chat_message_time"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentRight="true"
          android:layout_gravity="center_vertical"
          android:padding="10dp"
          android:text="2:46pm"
          android:textSize="@dimen/splash_4_user_name_text_size" /&gt;
  
      &lt;com.mypackage.RightBasedMessage
          android:id="@+id/chat_message_field"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:paddingBottom="@dimen/splash_3_comment_padding"
          android:paddingLeft="@dimen/splash_3_comment_end_padding"
          android:paddingRight="@dimen/chat_message_field_beginning_padding"
          android:paddingTop="@dimen/splash_3_comment_padding"&gt;
  
          &lt;TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Hi :)"
              android:textColor="@color/white_text_color" /&gt;
  
      &lt;/com.mypackage.RightBasedMessage&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Here is my Custom View:</p>
  
  <pre><code>public class RightBasedMessage extends RelativeLayout {
  
  private Paint paint;
  private Path path;
  private Point pointleftTop;
  private Point pointRightTop;
  private Point pointRightBottom;
  private Point pointLeftBottom;
  private float corner;
  private Context context;
  private int color = R.color.chat_my_message_field_color;
  
  public RightBasedMessage(Context context, AttributeSet attrs) {
      super(context, attrs);
      this.context = context;
      corner = getResources().getDimension(R.dimen.message_container_corner);
      paint = new Paint();
      path = new Path();
      paint.setStrokeWidth(5);
      paint.setStyle(Paint.Style.FILL);
      this.setWillNotDraw(false);
  }
  
  public void setMessageBackground(int color){
      this.color = color;
      invalidate();
  }
  
  @Override
  protected void onDraw(Canvas canvas) {
      super.onDraw(canvas);
      int width = getWidth();
      int height = getHeight();
  
      pointRightTop = new Point(width-(int)corner, (int)corner/2);
      pointRightBottom = new Point(width-(int)corner, height);
      pointLeftBottom = new Point(0, height);
      pointleftTop = new Point(0, 0);
      path.reset();
  
      path.moveTo(corner, 0);
      path.lineTo(width, 0);
      path.quadTo(pointRightTop.x, pointRightTop.y, width-corner, corner+corner/2);
      path.lineTo(width-corner, height-corner);
      path.quadTo(pointRightBottom.x, pointRightBottom.y, width - corner*2, height);
      path.lineTo(corner, height);
      path.quadTo(pointLeftBottom.x, pointLeftBottom.y, 0, height-corner);
      path.lineTo(0, corner);
      path.quadTo(pointleftTop.x, pointleftTop.y, corner, 0);
  
      paint.setColor(ContextCompat.getColor(context, color));
      canvas.drawPath(path, paint);
  
      path.close();
  }
  </code></pre>
  
  <p>}</p>