开发者

Text in TextView not shown in multiple lines - it gets truncated in a single line

Below is an outline of my layout. I have my ScrollView inside another LinearLayout because I would be adding more views to it in runtime.

Anyway, the problem is - the text in the TextView is always truncated to a single line, and is never shown in multiple lines.

Is there any way to make it display a multilined TextViw without having to set an arbitrary number of lines using android:lines or android:maxLines?

Thanks.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent" android:layout_height="fill_parent"
          android:orientation="vertical" android:background="@drawable/background"
          android:id="@+id/XyzLayout"
          android:paddingRight="10dp">

    <ScrollView android:layout_width="fill_parent"
            android:layout_height="fill_parent" android:background="@drawable/background"
            android:fillViewport="true">

        <LinearLayout android:layout_width="fill_parent"
                  android:layout_height="wrap_content" android:orientation="vertical"
                  android:layout_marginBottom="0dip" android:layout_marginTop="1dip">

            <TextView android:id="@+id/textView1"
                  android:text="@string/String1"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:开发者_运维百科layout_marginLeft="10dip"
                  android:layout_marginTop="20dip"
                  android:layout_marginRight="10dip" android:textSize="18dip"
                  android:typeface="sans" android:textStyle="bold"
                  android:layout_marginBottom="4dip"
                  android:inputType="text|textMultiLine"/>

            <TextView android:id="@+id/textView2"
                  android:text="@string/String2"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_marginLeft="10dip"
                  android:layout_marginTop="20dip"
                  android:layout_marginRight="10dip" android:textSize="16sp"
                  android:typeface="sans" android:textStyle="bold"
                  android:layout_marginBottom="4dip"
                  android:inputType="text|textMultiLine"/>
        </LinearLayout>
    </ScrollView>
</LinearLayout>


i've got this problem with a i5800 with CM7(2.3.7) and the emulator and works fine on a SGS-i9000 with CM9 (4.0.3).

The problem was setting the theme at the manifest:

 <application
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.DeviceDefault" >

I put " android:theme="@android:style/Theme.Holo " and if the device doesn't have it, the textview doesn't allow MultiLine.

You can use the library " holoeverywhere " to port the holo theme to all devices.

Regards.


Try deleting the setting android:inputType="text".

Just had the same problem. I had android:multiLines="2", then I tried android:lines="2", then tried adding android:singleLine="false", but still my EditText would only show one line. I could scroll horizontally to get to the end of my line. What ended up working was deleting the setting android:inputType="text" . This allowed me to type in a long line that would wrap around to a second line.


It could be false by default but did you try to add this in your TextView

 android:singleLine="false"

-serkan


To add to @KNU's answer...

Here's a good related answer showing that you can use a different theme depending on the version of Android it is running on - just create a versioned styles folder.

Answer here: TextView won't break text


Set input type as inputType="text|textMultiLine". This made to resolve my issue.

<TextView
    android:id="@+id/itemTitle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="text|textMultiLine"
    android:textSize="@dimen/text_size_12"
    android:layout_gravity="center"
    android:gravity="center"
    android:text="Your Text Here"/>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜