I am developing a messenger app in Android and for this I have a RelativeLayout containing the text message and some info about it. My current xml code for this looks as follows:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout android:id="@+id/text_message" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="6dp"> <RelativeLayout android:id="@+id/chat_message_inner" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/bubble_a1" android:padding="1dp"> <TextView android:id="@+id/text_message_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_gravity="center" android:layout_margin="5dp" android:text="Hello World" android:textColor="@android:color/black" android:textSize="@dimen/font_size"/> <RelativeLayout android:id="@+id/text_message_info" android:layout_width="45dp" android:layout_height="wrap_content" android:layout_toRightOf="@id/text_message_text" android:layout_toEndOf="@id/text_message_text" android:padding="3dp"> <TextView android:id="@+id/chat_timeStamp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/chat_status" android:text="00:00" android:textColor="@color/colorTimeStamp"/> <ImageView android:id="@+id/chat_status" android:layout_width="19dp" android:layout_height="13dp" android:layout_alignEnd="@+id/chat_timeStamp" android:layout_alignRight="@+id/chat_timeStamp" android:layout_marginEnd="2dp" android:layout_marginRight="2dp" android:layout_marginTop="6dp" android:src="@drawable/two_grey_hook"/> </RelativeLayout> </RelativeLayout> </RelativeLayout>
Small messages are looking good (Hello World Message), large messages reaching over multiple lines, however, make the information layout disappear (Longer Message). Is there a way of avoiding this problem? It doesn't really matter if I stick to RelativeLayouts or not, it just seemed for me to be the most customizable one.
Also, I know in this code extraction it seems like the two surrounding layouts can be merged into one, however, as I want to set the layout's gravity depending on who sent the message but don't want the background bubble to stretch over the whole width.
I would appreciate any kind of help and can also provide any further code snippets if you would like them.
Thanks GG15
No comments:
Post a Comment