1

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?

double-beep
  • 5,031
  • 17
  • 33
  • 41

1 Answers1

1

Correct me if I'm wrong but if you're talking about EditText you mean TextView right? And your problem is that the text displayed in the TextViews won't linebreak if they are too large to fit in? If yes you should probably add this:

android:inputType="textMultiLine"

to your TextViews.

And probably set the width of your LinearView which contains the txtChatConversationTo TextView to:

android:width="wrap_content" 
iQzero
  • 11
  • 1
  • yes it is TextView. but text is multiline and does not break but height of textView is same for all texts. i mean it size is constant and no change will be shown for any text. – MohammadReza Vahedi Jun 06 '14 at 11:51
  • Well, if you are using the Theme.Holo style you might want to read [this](http://stackoverflow.com/questions/11583261/textview-wont-break-text/13032036#13032036) – iQzero Jun 06 '14 at 12:27
  • i do changes but don't works for me! i want to have bubbles like viber and line in conversations view. – MohammadReza Vahedi Jun 07 '14 at 07:31