问题
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.
回答1:
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 (withparent="@android:style/Theme.Holo"
) - inside old
values
folder you'll put the 'plain' one, withparent="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
回答2:
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" />
来源:https://stackoverflow.com/questions/11583261/textview-wont-break-text