Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextView cuts off text when it is long enough

I have strange problem with TextView, it cuts off part of the text at the end. My layout looks like

<LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="top|center_horizontal"
        android:gravity="top|center_horizontal"
        android:orientation="vertical" >
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="top|center_horizontal"
            android:gravity="top|center_horizontal"
            android:orientation="horizontal"
            android:layout_weight="1"
            android:layout_marginBottom="5dp">
            <Button
                android:id="@+id/btnPreviousQuestion"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/selector_arrow_left"
                android:clickable="true"
                android:visibility="gone" >
            </Button>
            <TextView
                android:id="@+id/txtQuestion"
                style="@style/question_text"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:gravity="top|center_horizontal"
                android:layout_weight="1"
                 />
            <Button
                android:id="@+id/btnNextQuestion"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="10dp"
                android:background="@drawable/selector_arrow_right"
                android:clickable="true" >
            </Button>
        </LinearLayout>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_weight="1"
            android:orientation="horizontal" >
            <WebView
                android:id="@+id/wvMultimediaQuestion"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom|center_horizontal"
                android:layout_marginLeft="50dp"
                android:layout_marginRight="55dp"
                android:layout_weight="1"
                android:visibility="gone" />
        </LinearLayout>
    </LinearLayout>

and txtQuestion cuts off text when it is long enough. What is wrong, does anybody know ?

like image 762
Damir Avatar asked Dec 23 '11 13:12

Damir


3 Answers

Make use of these attributes

    android:lines="1"
    android:scrollHorizontally="true"
    android:ellipsize="end"

will append "..." at the end. But this will not solve problem in honeycomb tab

So for honeycomb tablet add the following atttibute also

android:singleLine="true" 

On the other hand if you require marquee effect

android:singleLine="true"
android:ellipsize="marquee" 
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true" 
android:focusable="true" 
android:focusableInTouchMode="true
like image 100
MGK Avatar answered Nov 15 '22 12:11

MGK


Yes there are some attributes you need to set, but first let us know what type of textview do you want exactly, single line or multi line?

There are some attributes you can take care of:

android:singleLine="true"  // or false
android:ellipsize="marquee"   // must check
android:lines="1"
like image 26
Paresh Mayani Avatar answered Nov 15 '22 12:11

Paresh Mayani


Set below properties in layout file. It works fine for me

android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:focusableInTouchMode="true"
like image 28
Namita S Avatar answered Nov 15 '22 12:11

Namita S