I am writing a chat application for learning Android programming in witch I will show the conversations between to users by a list. Any item of conversation list is a set of objects and a EditText
with a bubble background. But when I show the conversation the EditText
does not wrap it's content and the size of EditText
is same in all rows of conversation.
Here is my conversation item's code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/llmain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:ignore="UseCompoundDrawables" >
<TextView
android:id="@+id/txtTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/chatdate"
android:gravity="center"
android:textAlignment="gravity"
android:textSize="8sp" />
<ScrollView
android:id="@+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/llTo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/chatme"
android:gravity="top|right"
android:paddingTop="7dp"
android:textAlignment="gravity"
android:visibility="visible" >
<ImageView
android:id="@+id/imgStatusTo"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="bottom"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:scaleType="fitXY"
android:src="@drawable/wait_ic" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.82"
android:orientation="vertical" >
<ImageView
android:id="@+id/imgChatConversationToFile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:scaleType="fitCenter"
android:src="@drawable/ic_info" />
<TextView
android:id="@+id/txtChatConversationTo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="60dp"
android:autoLink="web"
android:background="@color/chatme"
android:drawableBottom="@color/jigari"
android:drawableLeft="@color/jigari"
android:drawableRight="@color/jigari"
android:drawableTop="@color/jigari"
android:gravity="right|top"
android:inputType="none"
android:linksClickable="true"
android:paddingLeft="20dp"
android:paddingRight="40dp"
android:paddingTop="5dp"
android:scrollHorizontally="false"
android:scrollbars="none"
android:selectAllOnFocus="true"
android:singleLine="false"
android:textDirection="rtl" />
</LinearLayout>
<ImageView
android:id="@+id/imgChatConversationTo"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="bottom"
android:layout_marginBottom="5dp"
android:background="@color/gray"
android:contentDescription="@string/user_image"
android:scaleType="fitXY"
android:src="@drawable/ic_user_image" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/llFrom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/chatyou"
android:paddingTop="7dp"
android:visibility="visible" >
<ImageView
android:id="@+id/imgChatConversationFrom"
android:layout_width="32dp"
android:layout_height="32dp"
android:background="@color/gray"
android:contentDescription="@string/user_image"
android:scaleType="fitXY"
android:src="@drawable/ic_user_image" />
<LinearLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.82"
android:orientation="vertical" >
<ImageView
android:id="@+id/imgChatConversationFromFile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:scaleType="fitCenter"
android:src="@drawable/ic_info" />
<TextView
android:id="@+id/txtChatConversationFrom1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginRight="60dp"
android:autoLink="web"
android:background="@color/chatyou"
android:gravity="top|right"
android:inputType="none"
android:linksClickable="true"
android:paddingLeft="45dp"
android:paddingRight="20dp"
android:paddingTop="3dp"
android:scrollHorizontally="false"
android:scrollbars="none"
android:selectAllOnFocus="true"
android:singleLine="false"
android:textAlignment="gravity" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
My problem is on txtConversationFrom
and txtConversationTo
.
At the code I will hide items that not required there.
How I can force EditText
to wrap text and resize to fit text size?