0

I have a custom dialog in which I displaying some text in the title bar. In android 4.0, it is truncating text. Only ... are appearing in next line. I am inflating following xml to dialog. It is working fine on 3.2.

I have tried layout_weight="1" and also android:ellipsize="none" but nothing is working

<LinearLayout
    android:layout_height="fill_parent"
    android:weightSum="1"
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:android1="http://schemas.android.com/apk/res/android"
    android:background="@drawable/rounded_textbox_base"
    android1:layout_width="fill_parent"
    android1:minWidth="500dp">
    <TableRow
        android:id="@+id/tableRow1"
        android1:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/rounded_button"
        android1:gravity="center"
        android:layout_weight="1">
        <TextView
            android:id="@+id/tv_nmp_needmore"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:layout_marginTop="10dp"
            android1:layout_marginLeft="20dp"
            android1:layout_marginRight="20dp"
            android:ellipsize="none"
            android:text=""
            android:textAppearance="?android:attr/textAppearanceLarge"
            android1:gravity="center"
            android1:textColor="@color/white" >
    </TextView>
    </TableRow>
    <LinearLayout
        android:id="@+id/linearLayout1"
        android:weightSum="1"
        android:layout_marginBottom="30dp"
        android:layout_marginTop="50dp"
        android1:layout_gravity="center"
        android1:gravity="center"
        android1:layout_width="wrap_content"
        android1:layout_height="wrap_content">
        <Button
            android:layout_height="wrap_content"
            android:id="@+id/btn_nmp_yes"
            android:background="@drawable/dialog_ok_button"
            android:layout_width="wrap_content">
        </Button>
        <TextView
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:id="@+id/textView1"
            android:text="OK"
            android:textStyle="bold"
            android:layout_marginLeft="20dp"
            android1:textColor="#000000">
        </TextView>
    </LinearLayout>
</LinearLayout>

Thanks, Manish

Manish
  • 983
  • 1
  • 9
  • 27
  • Have you tried adding "\n" in your string to force next line. – Guru Sep 23 '13 at 13:43
  • possible duplicate of [Android and displaying multi-lined text in a TextView in a TableRow](http://stackoverflow.com/questions/5230290/android-and-displaying-multi-lined-text-in-a-textview-in-a-tablerow) – Geobits Sep 23 '13 at 13:49
  • I want to wrap text automatically. putting "\n" at one particular position will be hardcoding. However I have tried it for text purpose and that is also not working. – Manish Sep 23 '13 at 13:57
  • @Geobits, I had checked that link but it is not helping in my case. I have also tried to replace tableLayout with linearLayout but nothing is working. Issue is coming only on >4.0 version – Manish Sep 23 '13 at 14:18

1 Answers1

0

You can use :

<TextView
    android:id="@+id/text" 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"  
    android:maxLines="2"/>

To limite the number of lines end wrap it between to ui elements, or you can have some fixe dimension in height or width. It will truncate the textview at the end with "...", but with this method you can't control when it break the line. It can truncate a word.

Second method would be to construc the string yourself before doing some textView.setText(...). You just have to determine the number max of char you want and then truncate the string yourself where you need and add "\n" when you need to break line.

An-droid
  • 6,433
  • 9
  • 48
  • 93
  • Hi Yume, I again observed my application. text is wrapping in next line but only ... are visible. Text is not visible. I have tried maxLine or \n but its not working. – Manish Sep 24 '13 at 11:26
  • Can you edit your question with concreate example of what is happening ? (with \n i think you should use StringBuilder) – An-droid Sep 24 '13 at 12:06
  • nice. To control how the line breaks you can use "Marquee" attribute of TextView – An-droid Feb 04 '14 at 08:38