2

I am having trouble with textView not breaking line before ICS. In ICS (i belive honeycomb works as well but i havent tried it tho) the text inside textView breaks nicely but in gingerbread and below text just keeps going in one line. Any ideas how to fix this?

I am using a viewpager and this is the layout for each screen. I am using custom textView just to add custom font, hope thats not the problem.

pager_item.xml:`

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
    android:padding="20dp" >

    <com.ursus.absolution.startme.MyTextView
        android:id="@+id/message_textview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/quotes_background"
        android:gravity="center"
        android:textColor="#585858"
        android:textSize="25dp" />

    <com.ursus.absolution.startme.MyTextView
        android:id="@+id/author_textview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:textColor="#585858"
        android:textSize="20dp" />

</LinearLayout>`

In ICS
_____________
|           |
|           |
| "This is  |
|  my cool  |
|   text"   |
|           |
|___________|

In gingerbread and below
_____________
|           |
|           |
| "This is my cool text"
|           |
|           |
|           |
|___________|

Sorry im new i cant post pictures. Thanks in advance, hope you guys get it.

///////UPDATE///////////////

Okay guys, this is very interesting.. i tried all your suggestions however neither has worked, so i started a new blank project and just put a textview into layout with really long string and it wrapped just fine.

So, i dont know how is this possible, but its the custom theme to style the actionbar doing this, when i comment it out in the manifest it works just fine, however the system holo theme seems doing this aswell

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ursus.absolution.startme"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />

<application
    android:icon="@drawable/iconn"
    android:label="@string/app_name"
    android:theme="@style/Theme.myStyle" >
    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main" >
    </activity>
    <activity
        android:name=".SplashScreenActivity"
        android:label="@string/title_activity_main"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

styles.xml

<resources>

<style name="Theme.myStyle" parent="@android:style/Theme.Holo">
    <item name="android:actionBarStyle">@style/mycoolstyle_transparent_ActionBar</item>
</style>

<style name="mycoolstyle_transparent_ActionBar" parent="@android:style/Widget.Holo.ActionBar">
    <item name="android:background">@drawable/transparent_actionbar</item>
</style>

...so when I add android:theme="@style/Theme.myStyle" in the manifest the textviews misbehave however when i add android:theme="@android:style/Theme.Holo" instead, as i normally would to force holo theme, it missbehave aswell

weird.

urSus
  • 12,492
  • 12
  • 69
  • 89
  • possible duplicate of [Android TextView Text not getting wrapped](http://stackoverflow.com/questions/2197744/android-textview-text-not-getting-wrapped) – wsanville Jul 20 '12 at 16:23
  • Try to add `android:singleLine="false` to your TextViews. `false` should be the default value but maybe something overrides it in your app. – Dalmas Jul 20 '12 at 16:26
  • A regular TextView will wrap automatically, so I assume the problem is with your custom TextView. If you only want to change fonts use `android:typeface=""`, as [discussed here](http://stackoverflow.com/q/2888508/1267661). If you still need help, post your MyTextView class so we can see what is happening. – Sam Jul 20 '12 at 16:27
  • Try wrapping your LinearLayout with a FrameLayout. I think it should work. Incase, you think its a problem with your custom TextView, check my tutorial out http://www.shubhayu.com/android/custom-control-extending-existing-views – Shubhayu Jul 20 '12 at 16:36
  • ...and on froyo it was really caused by the custom font, however that was not the case on gingerbread. – urSus Jul 20 '12 at 19:08

2 Answers2

8

This issue is reported in various forms, here and here for example. Many of the issues reports a previous working layout that gets broken when updating to ICS/holo theme.

I was able to reproduce it easily, it's a matter of a line of xml: @android:style/Theme.Holo

The easiest way to go around it is to introduce a versioned values folder, to let Android pick the right one. In other words You'll have 2 styles.xml:

  • inside values-v11 folder you should put the one you specified (with parent="@android:style/Theme.Holo")
  • inside old values folder you'll put the 'plain' one, with parent="android:Theme.Black.NoTitleBar".

Your manifest should remain unchanged, and Android will pick the right xml based on its version. The solution may not be the most elegant, but at least you won't mess with android:maxlines, android:width and so on

Community
  • 1
  • 1
Shine
  • 3,788
  • 1
  • 36
  • 59
  • OMG thank you so much for this! I have 2 identical apps, 1 free with ads, 1 paid. The TextView was showing correctly in the free one, but not the paid. Turns out I had `android:theme="@android:style/Theme.Holo"` in the manifest for the paid one, but not the free one... once I removed that, it worked! – Randy Dec 31 '12 at 15:47
0

In addition to Shine answer I had to set corresponding parameters to the TextView:

                android:ellipsize="none"
                android:maxLines="20"
                android:scrollHorizontally="false"
                android:singleLine="false" 

Example:

           <TextView                  
                android:textColor="@color/white"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:ellipsize="none"
                android:maxLines="20"
                android:scrollHorizontally="false"
                android:singleLine="false"
                android:text="@string/my_text" />
L. G.
  • 9,642
  • 7
  • 56
  • 78