xml - Android layout: chat bubble with date text in bottom right and baseline of message text -


this question has been asked many times never got correct answer.

how can build layout (that similar common messaging apps whatsapp, telegram) following characteristics:

  • it has view acts container , has background image of bubble.
  • in container there 2 elements, text message , text date.
  • the text message start top left , can have multiple lines.
  • the text date aligned baseline of last text message line, , on right of it.

i've tried reach relative layout.

<relativelayout android:id="@+id/message_bubble_container"     android:layout_below="@+id/message_date_separator_container"     android:layout_height="wrap_content"     android:layout_width="wrap_content"     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:background="@drawable/chat_message_background"     android:padding="4dp">       <relativelayout         android:layout_height="wrap_content"         android:layout_width="wrap_content">          <textview             style="@style/textappearance.appcompat.medium"             android:id="@+id/message_text"             android:layout_height="wrap_content"             android:layout_width="wrap_content"             tools:text="this message long causes date leave screen!" />          <textview             style="@style/textappearance.appcompat.small"             android:id="@+id/message_time"             android:layout_alignbottom="@id/message_text"             android:layout_height="wrap_content"             android:layout_torightof="@id/message_text"             android:textcolor="@color/material_grey_900"             android:textsize="12sp"             tools:text="18:58"             android:paddingleft="4dp"/>      </relativelayout>   </relativelayout> 

it works when text message on 1 single line, when grows fill width of container, pushes out date screen. how can avoid behavior , make text message keep margin on right date?

one line multiple lines

if css needed add margin-right: 40px; .message_text. of course android , not css so...

moreover, dislike use maxwidth on @id/message_text because don't know how many dp screen be.

lastly, i've heard talking flowlayout. there way?

thanks try solve problem affects tring develop chat layout.

use linear layout vertical orientation instead of relative layout. this:

<linearlayout android:id="@+id/message_bubble_container" android:layout_below="@+id/message_date_separator_container" android:layout_height="wrap_content" android:layout_width="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:background="@drawable/chat_message_background" android:padding="4dp">   <linearlayout     android:layout_height="wrap_content"     android:layout_width="wrap_content"     android:orientation="vertical">      <textview         style="@style/textappearance.appcompat.medium"         android:id="@+id/message_text"         android:gravity="right"         android:layout_height="wrap_content"         android:layout_width="wrap_content"         tools:text="this message long causes date leave screen!" />      <textview         style="@style/textappearance.appcompat.small"         android:id="@+id/message_time"         android:layout_alignbottom="@id/message_text"         android:layout_height="wrap_content"         android:layout_torightof="@id/message_text"         android:textcolor="@color/material_grey_900"         android:textsize="12sp"         tools:text="18:58"         android:paddingleft="4dp"/>  </linearlayout> </linearlayout> 

try, , let me know f worked. :)


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -