I want to implement this feature, as present in WhatsApp in Android.
Here, for implementing this I used separate TextViews for both text and time, placed inside a relative layout.
My Question is, how WhatsApp is deciding when to move the time in the new-line and when not.
Below are the Portrait and Landscape screenshot of WhatsApp.
Instinct feeling is, code must be something like this.
if(width_of_last_line_of_textview > some_fixed_value)
move time_textview to new-line;
else
make time_textview in-line;
But I was wondering if this can be done using xml (using some property weight etc)
WhatsApp bubble adjusts itself on every screen size, whether the screen is Landscape or Portrait.
Attached is the layout WhatsApp using for text bubble.
conversation_row_text_right.xml
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android" >
<com.whatsapp.DividerView
android:id="@id/date_divider"
style="@style/DateDivider" />
<LinearLayout
android:id="@id/main_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/date_divider"
android:layout_marginLeft="40.0dip"
android:minHeight="30.0dip"
android:orientation="vertical" >
<FrameLayout
android:id="@id/web_page_preview_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="4.0dip"
android:paddingLeft="8.0dip"
android:paddingRight="8.0dip"
android:paddingTop="8.0dip" />
<view
android:id="@id/text_content_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
class="com.whatsapp.TextAndDateLayout"
android:paddingBottom="2.0dip"
android:paddingRight="2.0dip" >
<com.whatsapp.TextEmojiLabel
android:id="@id/message_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:paddingBottom="3.0dip"
android:paddingLeft="8.0dip"
android:paddingRight="8.0dip"
android:paddingTop="2.0dip"
android:textColor="#ff000000"
android:textSize="@dimen/conversation_text_row_tv" />
<LinearLayout
android:id="@id/date_wrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center|right"
android:orientation="horizontal"
android:paddingBottom="1.0dip"
android:paddingRight="5.0dip" >
<TextView
android:id="@id/date"
style="@style/ConversationDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center|right"
android:gravity="right" />
<ImageView
android:id="@id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center|right"
android:paddingBottom="3.0dip"
android:paddingLeft="4.0dip" />
</LinearLayout>
</view>
</LinearLayout>
WhatsApp is using LinearLayout for Date, it contains TextView (for date i.e 3:48 PM) and ImageView (for icons i.e ✔)