Reputation: 7517
I am designing a chat item which should look similar to a whatsapp style chat interface but the problem is that the left side constraint does not seem to be working.
Here is my code.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.constraint.Guideline
android:id="@+id/left_guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.20" />
<LinearLayout
android:id="@+id/chat_bubble"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/chat_sender_bubble"
android:orientation="vertical"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintLeft_toRightOf="@id/left_guideline"
app:layout_constraintRight_toRightOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginEnd="22dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="22dp"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:orientation="vertical">
<ImageView
android:id="@+id/sender_image"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginBottom="5dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:adjustViewBounds="true"
android:background="@color/transparent"
android:scaleType="center"
android:src="@mipmap/ic_launcher"
android:visibility="gone" />
<TextView
android:id="@+id/sender_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginBottom="5dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:text="This is a really long message that could cross the
left guideline."
android:textColor="@color/senderBubbleTextColor" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginBottom="5dp"
android:orientation="horizontal">
<TextView
android:id="@+id/sender_timestamp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="27th june, 2017"
android:textColor="@color/senderBubbleTextColor"
android:textSize="12sp" />
<ImageView
android:id="@+id/synced"
android:layout_width="12dp"
android:layout_height="12dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="3dp"
android:layout_marginStart="3dp"
android:src="@drawable/clock"
android:tint="@color/senderBubbleTextColor" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
I have set a left guideline of 0.20 so it should never cross that but when there is a really long message,it does.If there is a better way of writing the xml it would be really helpful.
Upvotes: 2
Views: 6352
Reputation: 62831
Change the width of the LinearLayout
for chat_bubble to 0dp
. That will make that LinearLayout
stay between the left guideline and the right side of the parent.
<LinearLayout
android:id="@+id/chat_bubble"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@drawable/chat_sender_bubble"
android:orientation="vertical"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintLeft_toRightOf="@id/left_guideline"
app:layout_constraintRight_toRightOf="parent">
Upvotes: 11